Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
3 replies
bigsexy

Does a react Context component with a provider only get mounted when the provider is mounted?

ie does the code inside of say FooProvider
// ./FooContext.tsx
const FooContext = useContext()
export const FooProvider = () => {
  ...
  return (
    <FooContext.Provider value={...}>
      {children}
    </FooContext.Provider>
  )
}


only get ran whenever i use the provider somehwere in my App

// ./SomeRandomComponent.tsx
import {FooProvider} from "./FooContext.tsx"
const SomeRandomComponent = () => {
  ...
  return (
  <FooProvider>
    ...
  </FooProvider>
  )
}
Was this page helpful?