Skip to main content
Version: Next

Using Libraries

React Native provides a set of built-in Core Components and APIs ready to use in your app. You're not limited to the components and APIs bundled with React Native. React Native has a community of thousands of developers. If the Core Components and APIs don't have what you are looking for, you may be able to find and install a library from the community to add the functionality to your app.

Selecting a Package Manager​

React Native libraries are typically installed from the npm registry using a Node.js package manager such as npm CLI or Yarn Classic.

If you have Node.js installed on your computer then you already have the npm CLI installed. Some developers prefer to use Yarn Classic for slightly faster install times and additional advanced features like Workspaces. Both tools work great with React Native. We will assume npm for the rest of this guide for simplicity of explanation.

note

The terms "library" and "package" are used interchangeably in the JavaScript community.

Installing a Library​

To install a library in your project, navigate to your project directory in your terminal and run the installation command. Let's try this with react-native-webview:

npm install react-native-webview

The library that we installed includes native code, and we need to link to our app before we use it.

Linking Native Code on iOS​

React Native uses CocoaPods to manage iOS project dependencies and most React Native libraries follow this same convention. If a library you are using does not, then please refer to their README for additional instruction. In most cases, the following instructions will apply.

Run pod install in our ios directory in order to link it to our native iOS project. A shortcut for doing this without switching to the ios directory is to run npx pod-install.

npx pod-install

Once this is complete, re-build the app binary to start using your new library:

npm run ios

Linking Native Code on Android​

React Native uses Gradle to manage Android project dependencies. After you install a library with native dependencies, you will need to re-build the app binary to use your new library:

npm run android