Website Links

Monday 16 January 2017

React Native #5 - Installing/Uninstalling Modules using npm

One awesome thing about React Native is that you can use the npm to install packages which allow you to reuse JavaScript code that someone else has written(see here for list of packages)! This post will take you through how to install/uninstall packages.

Installing Packages

First, you will need to find a package you would like to install on the npm website. Once you find a package, go to your react native project's folder in the terminal and type:
npm install react-native-checkbox-field --save
--save means that the module you are installing will be automatically added to your package.json's dependencies. If you don't want your package.json to update, leave off the --save. After completing the install and updating your package.json, you can then use your new package as described on the packages page on the npm website, e.g:
import { CheckboxField, Checkbox} from 'react-native-checkbox-field';

Uninstalling Packages

Uninstalling packages is similar to installing packages. Go to your react native project's folder in the terminal and type:
npm uninstall react-native-checkbox-field --save
--save means that the module you are uninstalling will be automatically removed from your package.json's dependencies. If you don't want your package.json to update, leave off the --save. After completing the uninstall and updating your package.json, you will no longer have access to the package you have uninstalled so you should remove all references to it.

No comments:

Post a Comment