Bird
Raised Fist0
React Nativemobile~5 mins

Why native features differentiate mobile apps in React Native

Choose your learning style10 modes available
Introduction

Native features let mobile apps use the phone's special tools. This makes apps faster, easier to use, and more powerful.

When you want your app to use the camera to take pictures.
When your app needs to send notifications to the user.
When you want to access the phone's GPS to show location.
When you want smooth animations that feel natural on the device.
When you want your app to work offline using device storage.
Syntax
React Native
import { NativeModules, Platform } from 'react-native';

// Example to use a native feature
if (Platform.OS === 'android') {
  NativeModules.YourNativeModule.yourMethod();
}
NativeModules lets you call code written specifically for iOS or Android.
Platform.OS helps you check which device the app is running on.
Examples
Use the phone camera inside your app.
React Native
import { RNCamera } from 'react-native-camera';

<RNCamera style={{ flex: 1 }} />
Send a notification on iOS devices.
React Native
import PushNotificationIOS from '@react-native-community/push-notification-ios';

PushNotificationIOS.localNotification({
  alertTitle: 'Hello',
  alertBody: 'This is a notification',
});
Get the current location of the device.
React Native
import Geolocation from '@react-native-community/geolocation';

Geolocation.getCurrentPosition(position => {
  console.log(position.coords.latitude, position.coords.longitude);
});
Sample App

This app shows a button. When you press it, it shows a native alert message depending on your device type (Android or iOS). This uses native features for alerts.

React Native
import React from 'react';
import { View, Text, Button, Alert, Platform, NativeModules } from 'react-native';

export default function App() {
  const showNativeAlert = () => {
    if (Platform.OS === 'android') {
      Alert.alert('Native Feature', 'This is an Android alert!');
    } else {
      Alert.alert('Native Feature', 'This is an iOS alert!');
    }
  };

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text>Using Native Features in React Native</Text>
      <Button title="Show Native Alert" onPress={showNativeAlert} />
    </View>
  );
}
OutputSuccess
Important Notes

Native features make apps feel faster and more connected to the device.

Using native features may require extra setup for each platform.

React Native provides many built-in modules to access common native features easily.

Summary

Native features let apps use phone tools like camera, GPS, and notifications.

Using native features improves app speed and user experience.

React Native helps access native features with simple code.

Practice

(1/5)
1. Why do mobile apps that use native features like camera and GPS feel faster and smoother?
easy
A. Because native features use more internet data
B. Because native features run directly on the phone's hardware
C. Because native features require more battery power
D. Because native features are written in JavaScript only

Solution

  1. Step 1: Understand native feature execution

    Native features run directly on the phone's hardware, not through extra layers.
  2. Step 2: Compare with non-native features

    Non-native features often run in a slower environment like a web view, causing delays.
  3. Final Answer:

    Because native features run directly on the phone's hardware -> Option B
  4. Quick Check:

    Native features = direct hardware use = faster [OK]
Hint: Native means direct hardware use, so it's faster [OK]
Common Mistakes:
  • Thinking native features use more internet data
  • Confusing battery use with speed
  • Believing native features are only JavaScript
2. Which of the following is the correct way to import a native module in React Native?
easy
A. use Camera = import 'react-native-camera';
B. require('Camera').from('react-native');
C. import Camera from 'react-native-camera';
D. import { Camera } from 'react-native';

Solution

  1. Step 1: Recall React Native import syntax

    React Native uses ES6 import syntax like import Module from 'package';.
  2. Step 2: Check each option

    import Camera from 'react-native-camera'; matches correct syntax. Options A, B, and C are invalid or incorrect syntax.
  3. Final Answer:

    import Camera from 'react-native-camera'; -> Option C
  4. Quick Check:

    Correct import syntax = import Camera from 'react-native-camera'; [OK]
Hint: Use ES6 import syntax for native modules [OK]
Common Mistakes:
  • Using require incorrectly
  • Trying to destructure native modules not exported that way
  • Using invalid keywords like 'use'
3. What will this React Native code output when accessing the device's GPS location?
import { useEffect, useState } from 'react';
import { View, Text } from 'react-native';
import Geolocation from '@react-native-community/geolocation';

export default function Location() {
  const [location, setLocation] = useState(null);
  useEffect(() => {
    Geolocation.getCurrentPosition(pos => {
      setLocation(pos.coords.latitude + ', ' + pos.coords.longitude);
    });
  }, []);
  return {location ?? 'Loading...'};
}
medium
A. Crashes because useState is not defined
B. Shows an error because Geolocation is not imported
C. Immediately shows 'null' without location
D. Displays 'Loading...' then shows latitude and longitude

Solution

  1. Step 1: Analyze useEffect and Geolocation call

    On mount, getCurrentPosition runs and sets location state asynchronously.
  2. Step 2: Understand initial and updated state

    Initially, location is null, so 'Loading...' shows. After position is fetched, location updates to coordinates string.
  3. Final Answer:

    Displays 'Loading...' then shows latitude and longitude -> Option D
  4. Quick Check:

    Async location fetch = 'Loading...' then coords [OK]
Hint: Async state updates show loading first, then data [OK]
Common Mistakes:
  • Assuming location is available immediately
  • Forgetting to import Geolocation
  • Confusing null with error
4. This React Native code tries to use the camera but fails. What is the main error?
import { Camera } from 'react-native-camera';

export default function App() {
  return ;
}
medium
A. Camera is not a named export from 'react-native-camera'
B. Missing useState hook for Camera component
C. Camera component must be wrapped in a View
D. React Native does not support camera access

Solution

  1. Step 1: Check import statement correctness

    'react-native-camera' exports Camera as default, not named export, so import must be default.
  2. Step 2: Identify correct import syntax

    Correct import is import Camera from 'react-native-camera'; not destructured import.
  3. Final Answer:

    Camera is not a named export from 'react-native-camera' -> Option A
  4. Quick Check:

    Default export requires default import [OK]
Hint: Default exports need default import, not curly braces [OK]
Common Mistakes:
  • Using named import for default export
  • Assuming Camera needs useState
  • Thinking camera access is unsupported
5. You want to build a React Native app that uses the phone's native push notifications and GPS together. Which approach best ensures smooth performance and user experience?
hard
A. Use React Native libraries that wrap native modules for notifications and GPS
B. Write all features in JavaScript without native modules
C. Use web APIs inside a WebView for notifications and GPS
D. Only use GPS and skip notifications to reduce complexity

Solution

  1. Step 1: Understand native module benefits

    Native modules provide direct access to device features, improving speed and reliability.
  2. Step 2: Evaluate options for combining features

    Using React Native libraries that wrap native modules allows easy access to both notifications and GPS with good performance.
  3. Step 3: Reject less optimal choices

    Pure JavaScript or WebView approaches are slower and less reliable. Skipping features reduces app value.
  4. Final Answer:

    Use React Native libraries that wrap native modules for notifications and GPS -> Option A
  5. Quick Check:

    Native wrappers = best performance and UX [OK]
Hint: Use native wrappers for best speed and experience [OK]
Common Mistakes:
  • Trying to do everything in JavaScript only
  • Using WebView for native features
  • Avoiding features to reduce work
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard