React · Junior · Question 32 of 75
What steps are needed to pass data via Context?
- ✓Correct answer:
createContext→ a provider withvalue→useContextin a descendant - 2Declare a global variable in a module and import it into components
- 3Pass the data in
childrenof every component on the way down
Explanation
const ThemeContext = createContext('light') → <ThemeContext value={theme}> (in React 19 you can omit .Provider) → useContext(ThemeContext) in any descendant. When value changes, all components reading this context re-render.