Skip to content

Context

Share a value with every component below.

Create a context

createContext(defaultValue, name) returns a context. A component provides a value, and any component below it injects it. The default value is used when no component provides one.

const ThemeContext = createContext<Signal<'light' | 'dark'>>(undefined, 'Theme');

Provide and inject

Provide in setup(). Provide a signal when the value changes.

Required context

createRequiredContext(name) has no default. Injecting it with no provider above throws, which catches a missing provider early.