What are native modules?
- React Native course
- Advanced
- Lesson 67/83
- 5 min
Learn the native module concept.
What is a native module?
A native module is a bridge that exposes platform functions (camera, sensor, file system) inaccessible from JavaScript to JS. It is written in Objective-C/Swift (iOS) or Java/Kotlin (Android); React Native automatically exposes it as an object on the JS side. It is accessed via NativeModules.
Example: the device's battery level, Bluetooth state or a custom third-party SDK come as native modules. JS calls them as if they were ordinary objects. Behind the scenes the bridge relays the call to the UI thread and returns the result to JS. This way React Native goes beyond its limits.
Access via NativeModules
React Native exports NativeModules from the react-native package. This object carries all registered native modules. You import it with import { NativeModules } from 'react-native'; then access it like NativeModules.BatteryLevel.
The module name is given during native registration; the same name is used in JS. Calls are usually asynchronous; because they run on the UI thread and JS cannot return immediately. They are awaited or used as promises.
Practice Import NativeModules
Complete the empty file. Import NativeModules from react-native. Export it with export { NativeModules }.
Starter code
// import and export NativeModules from react-nativeSample solution
import { NativeModules } from 'react-native';
export { NativeModules };Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does a native module provide?
- Only animation
- Only defining styles
- Accessing platform functions from JS Correct answer
- Only network requests
Explanation: A native module provides access to platform functions from JS.
2 Import NativeModules
import { ____ } from 'react-native';
import { NativeModules } from 'react-native';
Explanation: NativeModules carries all native modules.
3 Match each part to its role
| Term | Meaning |
|---|---|
NativeModules |
Carries all modules |
NativeModules.Battery |
Accesses one module |
Objective-C/Swift |
iOS side |
Java/Kotlin |
Android side |