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>

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.

Further reading

Problem with a question

State Management · Middle · question 10

Test yourself

Take the State Management · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz