This repository provides a template for developing React applications powered by Rust code compiled to WebAssembly (Wasm). It enables seamless integration between high-performance Rust logic and a modern React frontend, allowing for rapid development and live updates in the browser.
This template demonstrates how to:
- Set up a Rust library for WebAssembly compilation
- Integrate the generated Wasm package into a React application
- Enable hot-reloading for both Rust and React code
Create a new Rust library project:
cargo new react-wasm-react --libUpdate the following files as needed:
Build the WebAssembly package using one of the following methods:
wasm-pack build --target webor
rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown --releaseInitialize a React project inside the rust-wasm-react folder:
npx create-react-app wwwAdd the generated Wasm package as a dependency in www/package.json:
"rust-wasm-react": "file:../pkg"
Install dependencies:
cd www
npm installUpdate App.js to initialize the Wasm library and call the exported Rust functions (e.g., greet).
Start the React development server:
npm startThe application will be available at http://localhost:3000.
This project is licensed under the MIT License. See the LICENSE file for details.
Maintained by mauroolivo and contributors.