React Native React Native Core Components & APIs 1 — Questions and Answers
Question 1: Which React Native component is the basic building block for creating UI layouts?
- View (Correct answer)
- Container
- Box
- Frame
Correct answer: View
View is the fundamental container component in React Native, equivalent to a div in web development.
Question 2: What prop is used to style a React Native component inline?
- className
- style (Correct answer)
- css
- theme
Correct answer: style
The style prop accepts a JavaScript object or StyleSheet reference to apply styles to React Native components.
Question 3: Which component is used to display scrollable lists efficiently in React Native?
- ScrollView
- FlatList (Correct answer)
- ListView
- List
Correct answer: FlatList
FlatList renders items lazily and only renders visible items, making it more performant than ScrollView for large lists.
Question 4: What is the purpose of the TouchableOpacity component in React Native?
- To make elements transparent
- To create pressable elements with opacity feedback (Correct answer)
- To animate views
- To create modal dialogs
Correct answer: To create pressable elements with opacity feedback
TouchableOpacity wraps elements to make them pressable and reduces their opacity when pressed, providing visual feedback.
Question 5: Which React Native API is used to handle device back button presses on Android?
- DeviceEventEmitter
- BackHandler (Correct answer)
- AndroidBack
- NavigationBack
Correct answer: BackHandler
BackHandler is the React Native API that listens for hardware back button presses on Android devices.
Question 6: What does the keyExtractor prop do in a FlatList component?
- Sorts list items by key
- Provides a unique key for each list item (Correct answer)
- Filters items by key value
- Groups items by category
Correct answer: Provides a unique key for each list item
keyExtractor is a function that returns a unique string key for each item, which React uses for efficient re-rendering.
Which React Native component is the basic building block for creating UI layouts?