createContext()
Create a context object that components can provide() and descendants can inject().
Signature
Section titled “Signature”function createContext<T>(defaultValue: T): Context<T>Parameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
defaultValue | T | Returned by inject() when no ancestor has called provide() |
Returns
Section titled “Returns”Context<T> — pass to provide() and inject().
Examples
Section titled “Examples”import { createContext, provide, inject, component, div, p } from "@whisq/core";
const ThemeCtx = createContext("light");
const Parent = component(() => { provide(ThemeCtx, "dark"); return div(Child({}));});
const Child = component(() => { const theme = inject(ThemeCtx); // "dark" return p(`Theme: ${theme}`);});See Components → Context for the full pattern.