Use npx userust <COMMAND> --help
to get more info about each command
Commands:
init: generate a new useRust hook
build: compile existing useRust hook
watch: compile hook after every code change
remove: remove installed useRust hook
Create useRust
hook by running npx userust init NAME
.
After that, the useRust
will be available:
import useRust from 'NAME'
//
const { rust, error, isLoading, init } = useRust({ autoInit })
rust: undefined until WebAssembly initializes. After initialization will contain all Rust functions with #[wasm_bindgen]
.
error: undefined or error raised during the initialization of WebAssembly.
isLoading: boolean whether Rust is being initialized currently.
init: a promise function without parameters that should be used to initialize the useRust hook, if autoInit has been set to false
autoInit: optional boolean, defaults to true. If true, the WebAssembly will start to initialize immediately after the component mounts. Value false
with init()
can be used to delay this initialization.
- HMR works well, if Vite is used and configured according to the instructions given during
npx userust init
- NextJS's
npm run dev
and Create React App'snpm start
do not refresh correctly afteruserust build
, and might need a restart after each recompilation
- If problems with Apple M1 installing wasm-pack: this might be helpful
- Yarn might have issues getting function type definitions, unknown reason so far