nethelper_wasm is a library that provides JavaScript-compatible wrappers for netcalc
logic, enabling its use in web apps.
This library exposes only the safe functions that can be used in JavaScript.
- Install
wasm-pack
by running the following command:cargo install wasm-pack
- Run
wasm-pack build --target web
to compile the library to WebAssembly.
After compiling the library with wasm-pack build --target web
:
- Navigate to your React project and open
package.json
- Under
"dependencies"
, add"wasm": "file:~/nethelper_wasm/pkg"
- In the root directory of your React project, run
npm install
- Import the functions you need in your React components with
import { function_name } from "wasm"
- Use the imported functions in your React components
- The file
package.json
is missing inside/pkg/
:
Follow this fix or manually create it.
Example package.json
{
"name": "nethelper_wasm",
"collaborators": [
"name <email>"
],
"version": "0.1.0",
"files": [
"nethelper_wasm_bg.wasm",
"nethelper_wasm.js",
"nethelper_wasm.d.ts"
],
"module": "nethelper_wasm.js",
"types": "nethelper_wasm.d.ts",
"sideEffects": false
}