React Native Technology & Digital Applications 2 — Questions and Answers
Question 1: Which React Native API allows you to detect whether the device is online or offline?
- NetInfo from @react-native-community/netinfo (Correct answer)
- NetworkState from react-native
- Connectivity from expo-connectivity
- InternetStatus from react-native-network
Correct answer: NetInfo from @react-native-community/netinfo
The @react-native-community/netinfo package provides the NetInfo API to monitor network connectivity state.
Question 2: What does the `useWindowDimensions` hook return in React Native?
- The width and height of the app window that update on rotation (Correct answer)
- Only the screen width as a static value
- The device's physical screen resolution in pixels
- The safe area insets for notched devices
Correct answer: The width and height of the app window that update on rotation
useWindowDimensions returns an object with width and height that automatically updates when the window size changes (e.g., on orientation change).
Question 3: In React Native, which component should you use to handle keyboard overlap with input fields?
- KeyboardAvoidingView (Correct answer)
- ScrollView with keyboardShouldPersistTaps
- SafeAreaView
- KeyboardDismissView
Correct answer: KeyboardAvoidingView
KeyboardAvoidingView automatically adjusts its height or padding when the keyboard appears, preventing inputs from being hidden.
Question 4: What is the purpose of the `Linking` API in React Native?
- To open URLs, deep links, and external apps like phone dialers or email clients (Correct answer)
- To link native modules to JavaScript at build time
- To create hyperlinks between screens in React Navigation
- To resolve symbolic links in the filesystem
Correct answer: To open URLs, deep links, and external apps like phone dialers or email clients
The Linking API handles outgoing deep links and universal links, letting you open URLs, phone numbers, or other apps.
Question 5: Which storage solution ships built-in with React Native for persisting small key-value data?
- AsyncStorage (Correct answer)
- SQLite
- SecureStore
- SharedPreferences
Correct answer: AsyncStorage
AsyncStorage is the built-in (now community-maintained) asynchronous, unencrypted key-value store for React Native apps.
Question 6: What does enabling Hermes as the JavaScript engine primarily improve in a React Native app?
- App startup time and memory usage on Android (Correct answer)
- Rendering speed of the Shadow Thread
- Network request throughput
- Metro bundler compilation speed
Correct answer: App startup time and memory usage on Android
Hermes is a JavaScript engine optimized by Meta to reduce TTI (time-to-interactive) and memory footprint, especially on Android.
Question 7: Which React Native API lets you vibrate the device?
- Vibration from react-native (Correct answer)
- HapticFeedback from react-native
- Motor from react-native-device
- Haptics from @react-native-community/haptics
Correct answer: Vibration from react-native
The Vibration API, imported directly from 'react-native', provides Vibration.vibrate() to trigger device vibration.
Which React Native API allows you to detect whether the device is online or offline?