Share a Theme with Context

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Share a light or dark theme with every component, however deep, without passing props down. Export a ThemeProvider component that renders its children, and a useTheme hook that returns an object { theme, toggleTheme }: theme is "light" to start, and toggleTheme() switches it between "light" and "dark". Every component inside the same ThemeProvider sees the same theme, and each ThemeProvider keeps its own. The default export App is a settings page for the preview; the checks only use ThemeProvider and useTheme.

Your code must pass

  • useTheme gives "light" inside a ThemeProvider
  • toggleTheme switches the theme for every component inside
  • Each ThemeProvider keeps its own theme