Last active
March 30, 2022 08:50
-
-
Save developerworks/11fb7da4edc55b0b3ff3810dcff3c965 to your computer and use it in GitHub Desktop.
useWasm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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