useMotionGPUUserContext + setMotionGPUUserContext provide a split read/write API for namespaced, reactive shared state within the MotionGPU runtime. In React, useSetMotionGPUUserContext provides a context-bound setter for effect and event-handler writes. In Vue and Svelte, use setMotionGPUUserContext directly.
This hook is exported from the advanced entrypoint:
The same entrypoint also exports scheduler helpers (applySchedulerPreset, captureSchedulerDebugSnapshot) for runtime diagnostics workflows.
Why use user context?
Standard framework context APIs (for example Svelte setContext/getContext or React context values) are usually static by design and tied to component hierarchy. The Motion GPU advanced API provides:
- Namespaced keys — multiple plugins write to different namespaces without conflicts.
- Explicit read/write split —
useMotionGPUUserContextreads;setMotionGPUUserContextwrites. - Conflict strategies —
skip,replace, ormergewhen a namespace already exists. - Reactive reads — values are backed by the
userstore fromuseMotionGPU().
API
Read the entire user context
Read a namespace
Write a namespace
The second argument is a value or factory function. Factory is only called if needed (based on conflict strategy). The return value is the effective value currently stored under the namespace.
SetMotionGPUUserContextOptions
Conflict strategies
Return value
The return value depends on the overload:
Practical patterns
Plugin initialization (skip if exists)
Plugin override (replace)
Partial updates (merge)
Consuming shared state
Effect/event writes
Full context read
Under the hood
User context is stored in the user CurrentWritable store exposed by useMotionGPU(). useMotionGPUUserContext provides namespaced read views, while setMotionGPUUserContext applies explicit writes with conflict-resolution rules.