File tree Expand file tree Collapse file tree 3 files changed +19
-20
lines changed Expand file tree Collapse file tree 3 files changed +19
-20
lines changed Original file line number Diff line number Diff line change 25
25
Learn how to configure a non-root public URL by running `npm run build`.
26
26
-->
27
27
< title > React App</ title >
28
- < script type ="text/javascript ">
29
- // set the pyodide files URL (packages.json, pyodide.asm.data etc)
30
- window . languagePluginUrl = 'https://cdn.jsdelivr.net/pyodide/v0.17.0/full/' ;
31
- </ script >
32
- < script src ="https://cdn.jsdelivr.net/pyodide/v0.17.0/full/pyodide.js "> </ script >
28
+ < script src ="https://cdn.jsdelivr.net/pyodide/v0.18.1/full/pyodide.js "> </ script >
33
29
</ head >
34
30
< body >
35
31
< noscript > You need to enable JavaScript to run this app.</ noscript >
Original file line number Diff line number Diff line change 1
1
import { useEffect , useState } from 'react' ;
2
- import script from './python/script .py' ;
2
+ import script from './python/main .py' ;
3
3
import logo from './logo.svg' ;
4
4
import './App.css' ;
5
5
6
- function App ( ) {
7
- const [ output , setOutput ] = useState ( "(loading...)" ) ;
6
+ const runScript = async ( code ) => {
7
+ const pyodide = await window . loadPyodide ( {
8
+ indexURL : "https://cdn.jsdelivr.net/pyodide/v0.18.1/full/"
9
+ } ) ;
8
10
9
- const runScript = code => {
10
- window . pyodide . loadPackage ( [ ] ) . then ( ( ) => {
11
- const output = window . pyodide . runPython ( code ) ;
12
- setOutput ( output ) ;
13
- } )
14
- }
11
+ return await pyodide . runPythonAsync ( code ) ;
12
+ }
13
+
14
+ const App = ( ) => {
15
+ const [ output , setOutput ] = useState ( "(loading...)" ) ;
15
16
16
17
useEffect ( ( ) => {
17
- window . languagePluginLoader . then ( ( ) => {
18
- fetch ( script )
19
- . then ( src => src . text ( ) )
20
- . then ( runScript )
21
- } )
22
- } )
18
+ const run = async ( ) => {
19
+ const scriptText = await ( await fetch ( script ) ) . text ( ) ;
20
+ const out = await runScript ( scriptText ) ;
21
+ setOutput ( out ) ;
22
+ }
23
+ run ( ) ;
24
+
25
+ } , [ ] ) ;
23
26
24
27
return (
25
28
< div className = "App" >
File renamed without changes.
You can’t perform that action at this time.
0 commit comments