Skip to main content
The outermost wrapper that loads the MuJoCo WASM module and provides it to all children.

Usage

Props

React.ReactNode
required
Child components that need access to MuJoCo.
(error: Error) => void
Called if the WASM module fails to load.
string
Custom URL for the single-threaded .wasm asset.
string
Custom URL for the multi-threaded .wasm asset.
(options?) => Promise<unknown>
Optional loader imported from @mujoco/mujoco/mt. It is supplied by apps that opt into threaded WASM.
"single" | "threaded" | "auto"
MuJoCo WASM build to load. Defaults to "single". "auto" selects the threaded build only when threadedLoader and mtWasmUrl are provided and the page is cross-origin isolated.
number
WASM initialization timeout in milliseconds.

Threaded WASM

The official @mujoco/mujoco package includes a multi-threaded WASM build in addition to the default single-threaded build. Import it only in apps that opt into it:
Forced threaded mode requires browser cross-origin isolation headers:

useMujocoWasm Hook

Access the WASM module status from any child component:

Return Value

Notes

  • Must wrap any component that uses MujocoCanvas or mujoco-react hooks
  • The WASM module is loaded once on mount from @mujoco/mujoco. The package ships the JavaScript bindings and .wasm asset.
  • Loading typically takes 1-3 seconds on first visit; subsequent visits use the browser cache