Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 819 Bytes

README.md

File metadata and controls

21 lines (17 loc) · 819 Bytes

Go Wasm React

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.

Key Parts

The key updates to the react app in client/ are the following:

  1. When building the main.wasm file, it is placed in client/public/
  2. Go's wasm_exec.js file was copied into client/public/ and then imported with <script> tags in client/public/index.html
  3. The main.wasm file was loaded and initialized in client/src/App.js

Using this App

Build the main.go file by doing the following:

  1. cd src/
  2. GOOS=js GOARCH=wasm go build -o ../client/public/main.wasm

Launch React App:

  1. cd client/
  2. yarn start