API reference · generated from source
Function: useRootContext()#
function useRootContext<T>(): T;Defined in: context.ts:217
Returns the container provided by the nearest RetreeProvider above the calling component.
Type Parameters#
| Type Parameter | Default type |
|---|---|
T | unknown |
Returns#
T
The container created by the nearest RetreeProvider's create
factory.
Remarks#
The default provider stores the container untyped, so the type argument is
asserted by the caller — TypeScript cannot verify it against the create
factory. Keep the type argument next to the factory (as in the example) or,
better, use createRetreeContext for a dedicated context whose
container type is inferred at every call site.
Throws#
When no RetreeProvider is mounted above the calling component.
Example#
const roots = useRootContext<{ counter: { count: number } }>();