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
What is the third argument to useReducer used for?
Answer: Lazy initialization of state via an init function
The optional third argument is an init function called with the second argument to lazily initialize state.
How does React compare Provider values to decide if consumers re-render?
Answer: Object.is (reference equality)
React uses Object.is to compare old and new context values, so new object literals always trigger re-renders.
Which pattern combines useContext and useReducer to mimic a Redux-like store?
Answer: Storing state and dispatch in a context Provider
Placing useReducer's state and dispatch into Context lets any descendant read and update shared state without prop drilling.
What happens if no Provider wraps a component that calls useContext?
Answer: The hook returns the default value passed to createContext
If no Provider is found, useContext returns the default value specified when the context was created.
In a useReducer action, what property typically identifies the type of state change?
Answer: action.type
By convention, actions have a type string that the reducer uses to determine which state transition to perform.
How do you pass additional data along with a useReducer action?
Answer: Include a payload property in the action object
A payload property on the action object carries the data needed by the reducer to update state.
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