A native module is a piece of code written in native platform languages (like Java for Android or Swift/Objective-C for iOS) that can be called from React Native JavaScript code to access platform-specific features.
Click to reveal answer
beginner
Why do we use native modules in React Native apps?
We use native modules to access device features or APIs that are not available in React Native's JavaScript environment, like sensors, camera controls, or advanced system functions.
Click to reveal answer
beginner
Which languages are used to write native modules for Android and iOS?
Android native modules are usually written in Java or Kotlin, while iOS native modules are written in Objective-C or Swift.
Click to reveal answer
intermediate
How does React Native communicate with native modules?
React Native uses a bridge to send messages between JavaScript and native code asynchronously, allowing JavaScript to call native functions and receive results.
Click to reveal answer
beginner
What is a common use case for creating a native module?
A common use case is when you need to use a device feature not supported by React Native, like accessing a custom Bluetooth API or advanced camera controls.
Click to reveal answer
What language is typically used to write native modules for iOS in React Native?
AJava
BJavaScript
CSwift
DKotlin
✗ Incorrect
Swift (or Objective-C) is used for iOS native modules, while Java or Kotlin is used for Android.
Why might you create a native module in a React Native app?
ATo replace React Native entirely
BTo improve JavaScript performance
CTo write UI components in native code
DTo access platform-specific features not available in React Native
✗ Incorrect
Native modules let you access device features or APIs that React Native does not support directly.
How does React Native communicate with native modules?
AUsing a bridge asynchronously
BDirect synchronous calls
CThrough REST API calls
DBy embedding native code in JavaScript
✗ Incorrect
React Native uses a bridge to communicate asynchronously between JavaScript and native code.
Which of these is NOT a typical language for writing native modules?
APython
BKotlin
CObjective-C
DJava
✗ Incorrect
Python is not used for native modules in React Native; native modules use platform languages like Java, Kotlin, Objective-C, or Swift.
What is the main benefit of using native modules?
AFaster JavaScript execution
BAccess to native device features
CSimpler app design
DNo need for native code knowledge
✗ Incorrect
Native modules allow React Native apps to access native device features not available in JavaScript.
Explain what a native module is and why it is important in React Native development.
Think about how JavaScript talks to native code to use device features.
You got /4 concepts.
Describe the process of creating and using a native module in a React Native app.
Consider the steps from native code to JavaScript usage.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of native modules in React Native?
easy
A. To access device features not available in JavaScript
B. To style components using CSS
C. To manage app navigation
D. To write UI components in JavaScript
Solution
Step 1: Understand React Native limitations
JavaScript in React Native cannot access all device hardware or OS features directly.
Step 2: Role of native modules
Native modules are written in native code to bridge this gap and provide access to those features.
Final Answer:
To access device features not available in JavaScript -> Option A
Quick Check:
Native modules = access device features [OK]
Hint: Native modules bridge JavaScript to device features [OK]
Common Mistakes:
Thinking native modules are for styling
Confusing native modules with navigation libraries
Believing native modules are UI components
2. Which syntax correctly imports a native module named CameraModule in React Native?
easy
A. import CameraModule from 'react-native';
B. import { NativeModules } from 'react-native'; const { CameraModule } = NativeModules;
C. const CameraModule = require('CameraModule');
D. import CameraModule from 'NativeModules';
Solution
Step 1: Recall native module import pattern
Native modules are accessed via the NativeModules object from 'react-native'.
Step 2: Correct destructuring syntax
We import NativeModules, then extract CameraModule from it using const { CameraModule } = NativeModules.
Final Answer:
import { NativeModules } from 'react-native'; const { CameraModule } = NativeModules; -> Option B
Quick Check:
NativeModules destructuring = correct import [OK]
Hint: Always import NativeModules then destructure [OK]
Common Mistakes:
Importing native module directly from 'react-native'
Using require without NativeModules
Wrong import source string
3. Given this code snippet, what will be logged if the native module method getBatteryLevel returns 85 asynchronously?
A. getCurrentLocation likely returns a Promise but is used synchronously
B. getCurrentLocation is not imported correctly
C. NativeModules cannot be destructured
D. console.log cannot print location objects
Solution
Step 1: Identify asynchronous method usage
Native module methods like getCurrentLocation usually return Promises.
Step 2: Check synchronous usage
The code assigns the Promise to location and logs it immediately, not waiting for resolution.
Final Answer:
getCurrentLocation likely returns a Promise but is used synchronously -> Option A
Quick Check:
Async method used without await or .then [OK]
Hint: Async native methods need await or .then [OK]
Common Mistakes:
Ignoring Promise nature of native methods
Trying to destructure NativeModules incorrectly
Assuming console.log can't print objects
5. You want to create a native module to access the phone's flashlight. Which steps are necessary to correctly use this native module in your React Native app?
hard
A. Write native code, but no need to register module or import it in JavaScript
B. Write JavaScript code only, import flashlight from 'react-native', call methods synchronously
C. Write native code for flashlight, register module, import NativeModules, call methods asynchronously
D. Use only React Native UI components, no native code needed
Solution
Step 1: Develop native code and register module
You must write native code (Java/Swift/Obj-C) to control flashlight and register it with React Native.
Step 2: Import and call from JavaScript
Import NativeModules, extract your flashlight module, and call its methods asynchronously.
Final Answer:
Write native code for flashlight, register module, import NativeModules, call methods asynchronously -> Option C