Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (userust) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
useRust
Add custom Rust WebAssembly hooks to React and SolidJS projects
// my-rust-code/src/lib.rs
#[wasm_bindgen]
pub fn add(a: i32, b: i32) -> i32 {
a + b
}import useRust from 'my-rust-code'
const Calculator = () => {
const { rust, error } = useRust()
return <div>1+1={rust?.add(1,1)}</div>
}How it works
- Have an existing React or SolidJS project
npx userust init NAMEwill compile and install a custom useRust hook to your project- Use it in your project:
import useRust from 'NAME' - Make changes to
./NAME/src/lib.rs npm run NAME:buildwill recompile the useRust hook
Alternatively you can use npm run NAME:watch to automatically recompile after changes to Rust code
Uses wasm-bindgen. See Rust code examples at its documentation page.
Features
- Leverage Rust and Wasm to speed up critical parts of your frontend
- Fully typed TypeScript interface, works in JavaScript projects as well
- No limitations for Rust code, provides a minimal, properly configured boilerplate to start with
- Develop frontend and Rust code from the same monorepo with a few simple commands
- Tested on Linux, MacOS and Windows
- npm, pnpm and yarn supported
- Simple interface inspired by SWR library
Licence
The MIT License.