-
Notifications
You must be signed in to change notification settings - Fork 8
/
App.js
39 lines (32 loc) · 863 Bytes
/
App.js
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
32
33
34
35
36
37
38
39
import { useEffect, useState } from 'react';
import script from './python/main.py';
import logo from './logo.svg';
import './App.css';
const runScript = async (code) => {
const pyodide = await window.loadPyodide({
indexURL : "https://cdn.jsdelivr.net/pyodide/v0.18.1/full/"
});
return await pyodide.runPythonAsync(code);
}
const App = () => {
const [output, setOutput] = useState("(loading...)");
useEffect(() => {
const run = async () => {
const scriptText = await (await fetch(script)).text();
const out = await runScript(scriptText);
setOutput(out);
}
run();
}, []);
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
5 + 7 = {output}
</p>
</header>
</div>
);
}
export default App;