Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/tiny-engine/llms.txt
Use this file to discover all available pages before exploring further.
createContext and useContext let you share a value with all descendant components in a scene-graph subtree without passing props manually through every layer. createContext produces a context object that includes a Provider JSX component; any component rendered inside that Provider can call useContext to read the provided value.
createContext
Signature
Parameters
The fallback value returned by
useContext when no matching Provider is found above the component in the scene graph.Return value
AContextCreated<T> object with two members:
| Member | Description |
|---|---|
Provider | A JSX component that accepts a value prop and a children prop. Wrap any subtree with it to inject the provided value. |
defaultValue | The default value supplied to createContext. |
useContext
Signature
Parameters
The context object returned by
createContext. Pass the same reference that was used to create the Provider.Return value
T — the value from the nearest Provider ancestor in the scene graph, or defaultValue if no provider is found.
Example — score context shared across components
GameScene.tsx
Example — theme / palette context
ThemeScene.tsx
Context values are not reactive by themselves. If you change the
value prop on a Provider, components that already consumed the context will not re-render automatically. To propagate updates reactively, store a SignalGetter (or an object containing signal getters) inside the context value, as shown in the GameScene example above. Consumers then call score() in a reactive position — a JSX prop or useEffect — to track changes.