JSPM

  • Created
  • Published
  • Downloads 49
  • Score
    100M100P100Q51795F
  • License MIT

Custom Rust WebAssembly hooks for React and SolidJS projects

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

    Custom Rust WebAssembly hooks for React and SolidJS projects

    pub fn add(a: i32, b: i32) -> i32 {
        a + b
    }

    $ npx userust build my-rust-code

    import useRust from 'my-rust-code'
    
    const Calculator = () => {
      const { rust, error } = useRust()
      return <div>{"1+1=" + rust?.add(1,1))}</div>
    }

    How it works

    1. Have an existing React, NextJS or SolidJS project
    2. npx userust init <MY_NAME> will generate, compile and install a custom useRust-hook to your project
    3. Make changes to ./<MY_NAME>/rust/
    4. npx userust build <MY_NAME> will recompile the useRust-hook

    Features

    • Blazingly fast Wasm code to speed up critical parts of your frontend
    • Fully typed TypeScript functions, uses wasm-bindgen inside (Works in JavaScript projects as well)
    • Handles the initial code generation and compilation after changes via CLI
    • The generated Rust code can be freely tweaked
    • Supports npm, pnpm and yarn
    • npx userust watch <MY_NAME> can be used to automatically compile after each code change

    Leverages wasm-bindgen. Simple interface heavily inspired by SWR library.

    Docs

    init, build, uninstall

    -y, --verbose, --no-typescript, manual delayed init with {autInit: false}

    Licence

    The MIT License.