Sample questions
Question 1Easy
Which API reports when the app moves to the background or returns to the foreground?
- BackHandler
- Dimensions
- Platform
- AppState
Answer: D. AppState
Explanation
AppState.addEventListener('change', ...) receives states such as 'active' and 'background'.
Step-by-step solution
- AppState reports whether the app is active, in the background or inactive.
- AppState.addEventListener('change', handler) receives each change.
- So option D is the correct answer.
Why the other options are wrong
- A. BackHandler handles the Android hardware back button.
- B. Dimensions gives the screen size, not the app state.
- C. Platform gives the platform name, not the app state.
Tip: Subscribe to AppState in useEffect and remove the listener in the cleanup.
Question 2Easy
What does useState(0) return?
- The number 0 and nothing else at all
- An object with get and set methods
- A Promise that resolves to 0
- An array: [current value, setter function]
Answer: D. An array: [current value, setter function]
Explanation
useState returns [value, setValue]. Calling the setter schedules a re-render with the new value.
Step-by-step solution
- useState(0) returns an array with two items.
- The first item is the current value and the second is the setter function.
- So option D is the correct answer.
Why the other options are wrong
- A. It returns an array, not only the number 0.
- B. It is not an object with get and set methods.
- C. It does not return a Promise.
Tip: Destructure it as const [value, setValue] = useState(initial).
Question 3Easy
Is the fetch API available for network requests in React Native?
- Yes, fetch is available globally
- No, only XMLHttpRequest works
- Only through a native module
- Only in the iOS simulator
Answer: A. Yes, fetch is available globally
Explanation
React Native provides fetch (and XMLHttpRequest) globally, so many web networking libraries also work.
Step-by-step solution
- React Native provides fetch as a global function.
- XMLHttpRequest is also available, so many web libraries work.
- So option A is the correct answer.
Why the other options are wrong
- B. Fetch is available, so the claim that only XMLHttpRequest works is false.
- C. Fetch is global, so no native module is needed.
- D. Fetch is not limited to the iOS simulator.
Tip: Use fetch with async and await for simple network requests.
Question 4Easy
How is an object usually saved with AsyncStorage?
- Pass the object directly; it is stored as is
- Convert it to a Buffer with
Buffer.from() - Call
object.toString() before saving it - Save
JSON.stringify(obj); JSON.parse on read
Answer: D. Save JSON.stringify(obj); JSON.parse on read
Explanation
AsyncStorage is a key-value store of strings, so structured data is serialised to JSON.
Step-by-step solution
- AsyncStorage stores strings as key-value pairs.
- An object must be converted to a JSON string before it is saved.
- So save JSON.stringify(obj) and read it back with JSON.parse; option D is the correct answer.
Why the other options are wrong
- A. Objects are not stored as they are; AsyncStorage keeps strings.
- B. Buffer.from is not the usual way to save an object in AsyncStorage.
- C. object.toString() gives the text '[object Object]' and loses the data.
Tip: Use JSON.stringify before setItem and JSON.parse after getItem.
Question 5Medium
A component subscribes with const sub = Keyboard.addListener('keyboardDidShow', fn) inside useEffect. What should the effect return?
- sub
- fn
- () => sub.remove()
- Nothing, as listeners clean up themselves
Answer: C. () => sub.remove()
Explanation
Returning a cleanup function removes the listener when the component unmounts, preventing leaks and calls on unmounted components.
Step-by-step solution
addListener returns a subscription.- An effect can return a cleanup function.
- The cleanup calls
sub.remove().
Why the other options are wrong
- A. Returning the sub object is not a function.
- B. fn is the handler, not a cleanup.
- D. Listeners leak unless removed.
Tip: Subscribe in effect, remove in cleanup.
Question 6Medium
Inside one onPress handler, setCount(count + 1) is called twice. count was 0. What is count after the re-render?
- 2
- 0
- 1
- It depends on the platform
Answer: C. 1
Explanation
Both calls read the same count (0) from that render, so both set 1. Use the updater form setCount(c => c + 1) to get 2.
Step-by-step solution
- Both calls read count from the same render, where count is 0.
- Each call sets the value to 0 + 1, which is 1.
- The final count is 1, so option C is the correct answer.
Why the other options are wrong
- A. 2 needs the updater form, because the second call still reads the old 0.
- B. The state is set to 1, so it is not left at 0.
- D. The result does not depend on the platform.
Tip: When the new value depends on the old one, use the updater form setCount(c => c + 1).
Question 7Medium
What does Fast Refresh do when you save an edit to a function component?
- Updates the UI, usually keeping component state
- Rebuilds and reinstalls the whole native app
- Resets every screen and clears all app state
- Only reloads styles, never component logic
Answer: A. Updates the UI, usually keeping component state
Explanation
Fast Refresh re-runs the edited module and re-renders, preserving hook state where it can. Native changes still need a rebuild.
Step-by-step solution
- Fast Refresh re-runs the edited module after you save.
- It re-renders the component and keeps hook state where it can.
- So option A is the correct answer.
Why the other options are wrong
- B. Fast Refresh does not reinstall the native app; native changes still need a rebuild.
- C. It does not reset every screen or clear app state.
- D. Component logic is updated too, not only styles.
Tip: JS and UI edits refresh on save; native code changes still need a rebuild.
Question 8Medium
Why is useWindowDimensions() often better than calling Dimensions.get('window') once at module load?
- It returns sizes in physical pixels rather than dp
- It works without a component, at module scope
- It re-renders when the window size changes
- It also returns the device's model and OS name
Answer: C. It re-renders when the window size changes
Explanation
A value read once at module load goes stale after rotation or resizing. The hook subscribes to changes and updates the component.
Step-by-step solution
- Dimensions.get at module load runs once.
- useWindowDimensions is a hook that subscribes to changes.
- The component re-renders on rotation or resize.
Why the other options are wrong
- A. Both use density-independent units.
- B. A hook only works inside components.
- D. It returns width, height, scale and fontScale only.
Tip: Need live size, use the hook.
Question 9Hard
Why is an Animated.Value usually created with useRef(new Animated.Value(0)).current?
- So the animation runs on a background thread
- Because Animated.Value cannot be placed in state
- So the same value persists across re-renders
- So the value resets to 0 on every render
Answer: C. So the same value persists across re-renders
Explanation
A ref keeps one instance for the component's lifetime. Creating it directly in the body would make a new value on each render and break running animations.
Step-by-step solution
- UseRef returns the same object on every render.
- The Animated.Value stored in it therefore persists across re-renders.
- So option C is the correct answer.
Why the other options are wrong
- A. UseRef does not move the animation to a background thread.
- B. An Animated.Value can be stored in state; that is not why useRef is used.
- D. A ref keeps its value, so the value does not reset on each render.
Tip: Create long-lived animated values with useRef so they survive re-renders.
Question 10Hard
useEffect(() => {
const id = setInterval(() => setCount(count + 1), 1000);
return () => clearInterval(id);
}, [])
runs with count starting at 0. What does the screen show after 5 seconds?
- 5
- 1
- 0
- It keeps rising, but 2 at a time
Answer: B. 1
Explanation
The interval callback closes over count from the first render, which is 0, so every tick sets 1. setCount(c => c + 1) or adding count to the deps fixes it.
Step-by-step solution
- The effect runs once because the dependency array is empty.
- The interval callback keeps the count from the first render, which is 0.
- Each tick sets the count to 0 + 1, so after 5 seconds the screen shows 1, which is option B.
Why the other options are wrong
- A. 5 would need the callback to read the latest count, and it does not here.
- C. The first tick sets the count to 1, so the screen does not stay at 0.
- D. The value does not rise; every tick sets the same 1.
Tip: Inside an interval, use setCount(c => c + 1) or add the dependency so the latest value is read.
Practise all 15 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →