Skip to content

A really minimal and documented example of golang, react, and typescript all working together and making JS calls across a bridge to go

Notifications You must be signed in to change notification settings

Rob117/wasm-golang-react-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is this

Run Go code, using web assembly, in a React app that uses typescript. This is the minimum proof of concept that I could get working.

How do I use this

yarn build yarn start

Positives

You can run go code. That's pretty cool, and lets you port your go applications really easily using the web.

You can call that Go code from Javascript.

You can do things to JS from Go Code. Small example of an alert

Negatives

When you are done using a function and it will never be called again, you have to call Func.Release or the memory won't be freed up

Funcs can deadlock really easily, apparently - See this

The LoadWasm component and wasm_exec.js is just a huge bundle of boilerplate

Type safety in Go when crossing the JS bridge is annihilated. Go can't ensure anything about what is coming across that bridge, so the only args that can be used when defining bridge functions are []js.Value. There are a lot of methods on js.Value (.IsNumber, IsUndefined, etc.) to help you with this, but there is going to be a lot of conversion on your part.

The best way to handle this seems to just be minimizing what you pass back-and-forth between go and js, for the most part. This should be entirely possible - if you've worked with React Native and native modules, it should be a similar feeling.

Threads don't seem to really exist in the go implementation? Based on golang/go#28631 and https://news.ycombinator.com/item?id=30357078, it might be doable, but I really don't know.

Acknowledgements

Created while reading the following:

https://dev.to/royhadad/how-to-create-a-react-app-with-go-support-using-webassembly-in-under-60-seconds-4oa3 https://xebia.com/blog/golang-webassembly/

About

A really minimal and documented example of golang, react, and typescript all working together and making JS calls across a bridge to go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published