JSPM

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

Use Rust bindgen WASM as a React (or SolidJS) hook

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

    Example https://cmdcolin.github.io/posts/2022-08-22-rustwasm

    wasm-pack build --target web ./localrust

    TODO

    • inquirer

      • React / SolidJS
      • TypeScript / JavaScript (save response)
      • .gitignore compiled wasm code and bindings yes/no (save response)
      • run: npm install ./name / run later by myself (or I use yarn/pnpm) (CHANGE DIR STRUCTURE) (check if has all)
      • run: npx build name / run later by myself
      • show code example!
    • --no-typescript option

    • autodetect react, solidjs

    • detect package-lock.json, pnpm.lock, yarn.lock (multiple versions)

    • test yarn 1 and 2, does it update when rebuild?

    • Generated using useRust version .....

    • make sure there is a package.json before start

    --verbose, hide default logs which successfull

    import useRust from 'my-rust-calculator'
    
    const Calculator = () => {
      const { rust, error } = useRust()
    
      if (error) return <div>failed to load</div>
      if (!rust) return <div>loading...</div>
      return <div>1+1={rust.add(1,1)}!</div>
    }
    import useRust from 'my-rust-calculator'
    
    const Calculator = () => {
      const { rust, error } = useRust()
    
      if (error()) return <div>failed to load</div>
      return <div>1+1={rust()?.add(1,1) || "loading..."}!</div>
    }