State Management · Junior · Question 19 of 75
What are the steps to use Context?
- ✓Correct answer:
createContext→ wrap the tree in a provider withvalue→ read withuseContext - 2
useContextin the root →createContextin each child → passvalueas a prop - 3Declare a global variable and import it into every component
Explanation
const ThemeContext = createContext('light'); in React 19 you can render <ThemeContext value={theme}> directly (earlier versions used <ThemeContext.Provider>); any descendant calls useContext(ThemeContext).