Linking Native Dependencies in React Native
Installing a native library is a two-step process: fetch the JS code, then link the native iOS/Android parts. This is required for packages like react-native-webview that need native APIs. The footgun is forgetting to run pod install for iOS and rebuild.
Why it exists
React Native provides core components, but real-world apps often need functionality not included, like web views or advanced maps. These features require access to native platform APIs, which pure JavaScript libraries cannot provide. Linking bridges this gap, connecting third-party native code to your React Native project.
The mental model
Think of it like adding a specialized hardware component to your computer. You don't just place the component inside the case; you also have to connect it to the motherboard and install its drivers. In React Native, npm install is like placing the component in the case. Linking (pod install for iOS, Gradle sync for Android) is connecting it to the motherboard, and rebuilding the app is like installing the drivers so the OS can use it.
How it works
When you install a library with native code, the JavaScript part is added to your node_modules folder. For iOS, React Native uses CocoaPods as the dependency manager. Running npx pod-install updates your ios/Podfile.lock and integrates the new library's native code into your Xcode workspace. For Android, the Gradle build system automatically detects and links the new dependency when you rebuild the app. In both cases, a full application rebuild (npm run ios or npm run android) is required to compile the new native code into the final app binary.
When to use it
You must link dependencies whenever you install a React Native library that is not 100% JavaScript. This is common for packages that interact with device hardware (camera, GPS), use platform-specific UI elements (like a web view), or perform heavy computations that are faster in native code. The library's documentation will almost always specify if native linking is required.
When not to use it
This process is unnecessary for pure JavaScript libraries. Packages like lodash or state management libraries like zustand work in any JavaScript environment and don't have native components. Installing them with npm or yarn is sufficient. Trying to link a pure JS library will have no effect, and you only need to restart your bundler, not rebuild the entire app.
One canonical example
To add a web view to your app, you install react-native-webview by running npm install react-native-webview. This is not enough. To link it on iOS, you must run npx pod-install from your project root. Then, you rebuild the app with npm run ios. For Android, you simply need to rebuild after the install: npm run android. Only after these steps can you import and use the <WebView /> component in your code.
Interview question
What is the primary function of "linking" a native dependency in a React Native application?
- a.To automatically generate the necessary JavaScript wrappers for native APIs, eliminating manual coding.
- b.To update the project's node_modules directory with the latest native library files.
- c.To compile the JavaScript code of the library into platform-specific native modules for faster execution.
- d.To connect the native platform-specific code of the library to the React Native project's build system and runtime bridge.Correct
Why? this is the answer
Linking integrates the native code (like from CocoaPods for iOS or Gradle for Android) into the project's build system, making it accessible to the React Native bridge. Option C is incorrect because linking does not compile JavaScript; it connects existing native code.
Just read this? Test yourself on what you have been reading.
Read the original → reactnative.dev
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on react native — each one lists the topics its interview covers.
See open roles