Context

is an externally declared state object declared via . The Provider property is a component that acts as a 'host' of the context, that is initialized with it's own value.

Children of the provider can use useContext to access the provider's current state - if no provider is found, it will return the context's initial value.

Example

import { ThemeContextProvider } from "./ThemeContextProvider"
import { Button } from "./Button"

function App() {
  return (
    <ThemeContextProvider>
      <Button />
    </ThemeContextProvider>
  )
}

Related