React Native React Native State Management & Performance 1 — Questions and Answers
Question 1: Which React hook is used to manage local component state in React Native?
- useLocalState
- useState (Correct answer)
- useStore
- useData
Correct answer: useState
useState returns a state variable and a setter function, enabling functional components to manage local reactive state.
Question 2: What is the primary purpose of the useEffect hook in React Native?
- To add visual effects to components
- To perform side effects like API calls and subscriptions (Correct answer)
- To memoize expensive computations
- To manage global state
Correct answer: To perform side effects like API calls and subscriptions
useEffect runs side effects after render, such as fetching data, setting up subscriptions, or directly manipulating the DOM.
Question 3: Which library provides a global state management solution commonly used in React Native apps?
- ReactStore
- Redux (Correct answer)
- GlobalState
- AppContext
Correct answer: Redux
Redux is a predictable state container that manages global application state using actions, reducers, and a single store.
Question 4: What does the useMemo hook do in React Native?
- Stores persistent data between sessions
- Memoizes the result of an expensive computation (Correct answer)
- Manages async state updates
- Creates memoized callback functions
Correct answer: Memoizes the result of an expensive computation
useMemo caches the result of a computation and only recalculates when its dependency array changes, preventing unnecessary recalculations.
Question 5: What is the Context API used for in React Native?
- Connecting to external APIs
- Sharing state across components without prop drilling (Correct answer)
- Managing async operations
- Handling device context like orientation
Correct answer: Sharing state across components without prop drilling
Context API allows data to be passed through the component tree without explicitly passing props at every level.
Question 6: Which hook from Redux Toolkit allows a component to read from the Redux store?
- useStore
- useSelector (Correct answer)
- useState
- useRedux
Correct answer: useSelector
useSelector subscribes a component to the Redux store and returns the selected slice of state, re-rendering when that slice changes.
Which React hook is used to manage local component state in React Native?