Lifting State and Context API Quiz
Six drills on lifting state to a common ancestor, when to switch to Context, and the useReducer + useContext pattern for a small, self-contained store.
1,149 views
17
Two <TempInput> components need to stay in sync (celsius and fahrenheit). Lift the temperature into a <TempConverter> parent and pass a setter down to both children.
What is the exact problem Context solves, and what is the cost of using it? Two sentences.
Build a ThemeProvider with a context exposing the current theme and a switcher, then consume it inside a <ThemedButton> using useContext.
In a legacy class component, how do you read context without useContext? Show the contextType pattern.
Combine useReducer and useContext to expose a tiny <TodosProvider> plus a useTodos() hook. The hook returns { todos, add, toggle }.
A Context value of { user, setUser } is rebuilt on every parent render. Every consumer in the tree re-renders even when user is the same object as before. What is the fix?
