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:
useMujocoWasm Hook
Access the WASM module status from any child component:Return Value
Notes
- Must wrap any component that uses
MujocoCanvasor mujoco-react hooks - The WASM module is loaded once on mount from
@mujoco/mujoco. The package ships the JavaScript bindings and.wasmasset. - Loading typically takes 1-3 seconds on first visit; subsequent visits use the browser cache
threadCount defaults to 0. Set a positive integer to initialize mju_threadpool
for each simulation data instance. It requires the threaded build and cross-origin
isolation. Loading the MT build alone does not request a simulation thread pool.
Benchmark your scene before increasing the count; small scenes can be slower.