State Management · Middle · Question 10 of 75
What happens with nested providers of the same context?
<ThemeContext value="dark">
<Sidebar />
<ThemeContext value="light">
<Panel />
</ThemeContext>
</ThemeContext>- ✓Correct answer:
Panelreads"light"- the nearest provider wins - 2
Panelreads"dark"- the outermost provider wins - 3React throws an error about duplicate providers
Explanation
useContext looks up to the closest provider. Overriding a value for a subtree is a legitimate pattern: a dark section inside a light page, a nested form with its own settings.