This is a basic example of using a go wasm file in a react app. There is a
main.go
file in the src/
directory and a react app in the client/
directory. This Repo is an example of how to build a go wasm
from and call
a method from a react app.
The key updates to the react app in client/
are the following:
- When building the
main.wasm
file, it is placed inclient/public/
- Go's
wasm_exec.js
file was copied intoclient/public/
and then imported with<script>
tags inclient/public/index.html
- The
main.wasm
file was loaded and initialized inclient/src/App.js
Build the main.go
file by doing the following:
cd src/
GOOS=js GOARCH=wasm go build -o ../client/public/main.wasm
Launch React App:
cd client/
yarn start