/
WasmLoader.jsx
31 lines (24 loc) · 910 Bytes
/
WasmLoader.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { useEffect } from "react";
import { useWindowContext } from "./WindowContext";
const WasmLoader = () => {
const window = useWindowContext();
useEffect(() => {
if (!window.Go) {
const script = document.createElement("script");
script.onload = async function() {
const go = new window.Go();
const webAssembly = await window.WebAssembly.instantiateStreaming(
window.fetch("/public/wasm/main.wasm"),
go.importObject
);
go.run(webAssembly.instance); // populates window.UnitaryNDilation
};
script.src = "/public/wasm/wasm_exec.js";
script.type = "text/javascript";
document.head.appendChild(script);
}
}, []);
return null;
};
WasmLoader.displayName = "WasmLoader";
export default WasmLoader;