Skip to content

Instantly share code, notes, and snippets.

@developerworks
Last active March 30, 2022 08:50
Show Gist options
  • Save developerworks/11fb7da4edc55b0b3ff3810dcff3c965 to your computer and use it in GitHub Desktop.
Save developerworks/11fb7da4edc55b0b3ff3810dcff3c965 to your computer and use it in GitHub Desktop.
useWasm
// src/useWasm.js
export const useWasm = (fileName, imports) => {
const [state, setState] = useState(null);
useEffect(() => {
const fetchWasm = async () => {
const wasm = await fetch(fileName);
const instance = await AsBind.instantiate(wasm, imports);
setState(instance);
};
fetchWasm();
}, []);
return state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment