useContext and useReducer Flashcards
6 cards from real React practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 useContext and useReducer flashcards as text
Which hook do you use inside a component to read a context value?
Answer: useContext
The useContext hook is the built-in React hook for reading a context value inside a function component.
How do you update context value from a child component?
Answer: Provide a setter or dispatch function as part of the context value
Including an updater function (setState or dispatch) in the context value allows consumers to trigger changes.
What performance optimization prevents context consumers from re-rendering when unrelated state changes in the Provider?
Answer: Memoizing the context value with useMemo
Wrapping the context value in useMemo ensures the same reference is passed unless the actual data changes.
What is the immer library often used for with useReducer?
Answer: Writing reducers with mutable syntax that produce immutable state
Immer lets you write reducer logic as if you are mutating state, while actually producing a new immutable state.
Can you call dispatch from inside a useEffect?
Answer: Yes, and dispatch is stable so it won't need to be in the dependency array
React guarantees dispatch identity is stable across renders, so it does not need to be listed as a dependency.
How should you pass context to a deeply nested child?
Answer: Wrap ancestor components in the Context Provider and consume with useContext
Wrapping the ancestor with a Provider and calling useContext in the descendant eliminates prop drilling.
Written and edited by Nathan Beja, founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy