MCPcopy Create free account
hub / github.com/callstackincubator/polygen / FetchModuleExample

Function FetchModuleExample

apps/example/src/examples/FetchExample.tsx:4–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { Button, StyleSheet, Text, View } from 'react-native';
3
4export default function FetchModuleExample() {
5 const [module, setModule] = useState<WebAssembly.Module>();
6 const loadModule = useCallback(async () => {
7 setModule(
8 await WebAssembly.compileStreaming(
9 fetch('http://localhost:8000/example.wasm')
10 )
11 );
12 }, []);
13
14 return (
15 <View style={styles.container}>
16 <Text>
17 Before loading, make sure you have a server running at
18 http://localhost:8000 that serves src/directory
19 </Text>
20 <Text>
21 You can do this by running e.g. `python3 -m http.server` in src
22 directory.
23 </Text>
24 <Button title="Load valid module" onPress={loadModule} />
25 <Text>Loaded: {module ? 'true' : 'false'}</Text>
26 {!!module && (
27 <Text>
28 Exports: {JSON.stringify(WebAssembly.Module.exports(module))}
29 </Text>
30 )}
31 </View>
32 );
33}
34
35const styles = StyleSheet.create({
36 container: {

Callers

nothing calls this directly

Calls 1

exportsMethod · 0.80

Tested by

no test coverage detected