inject()
Read the value of a context provided by an ancestor. Call from inside a component() setup. Returns the context’s defaultValue when no ancestor has called provide().
Signature
Section titled “Signature”function inject<T>(context: Context<T>): TParameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
context | Context<T> | The context object returned by createContext() |
Returns
Section titled “Returns”T — the nearest ancestor’s provided value, or the context’s default if none.
Examples
Section titled “Examples”import { createContext, inject, component, p } from "@whisq/core";
const ThemeCtx = createContext("light");
const Child = component(() => { const theme = inject(ThemeCtx); return p(`Theme: ${theme}`);});See provide() for the producer side and Components → Context for the full pattern.