-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Advice in support in Vite #341
Comments
Hi, when trying out |
Hi, I created a minimum test project using React code (App.jsx)import { useState, useEffect } from "react";
import { PythonProvider } from "react-py";
import { usePython } from "react-py";
import "./App.css";
function Codeblock() {
const [input, setInput] = useState("");
// Use the usePython hook to run code and access both stdout and stderr
const { runPython, stdout, stderr, isLoading, isRunning } = usePython();
return (
<>
{isLoading ? <p>Loading...</p> : <p>Ready!</p>}
<form>
<textarea
onChange={(e) => setInput(e.target.value)}
placeholder="Enter your code here"
/>
<input
type="submit"
value={!isRunning ? "Run" : "Running..."}
disabled={isLoading || isRunning}
onClick={(e) => {
e.preventDefault();
runPython(input);
}}
/>
</form>
<p>Output</p>
<pre>
<code>{stdout}</code>
</pre>
<p>Error</p>
<pre>
<code>{stderr}</code>
</pre>
</>
);
}
function App() {
useEffect(() => {
navigator.serviceWorker
.register("/react-py-sw.js")
.then((registration) =>
console.log(
"Service Worker registration successful with scope: ",
registration.scope
)
)
.catch((err) => console.log("Service Worker registration failed: ", err));
}, []);
return (
<>
<PythonProvider>
<Codeblock />
</PythonProvider>
</>
);
}
export default App; File Structure
However, it is possible to host With an error. In contrast, my approach Hosting page: https://siraisinotes-demo.web.app/reactpy_clone
|
Hi,
I planned to execute Python code on my React and I tried multiple versions of React hooks and js libraries. I also tried this one sometime before but it does not work directly in Vite. Then I did quite a bit of research and managed to get Pyodide Ver 0.25 worker embedded in my React project (can execute code and install package). I may not be able to provide PR but I can provide my version of worker to provide some insights to make a Vite version of this work directly.
My Pyodide worker: https://github.com/siraisisatoru/react-markdown-template/blob/main/src/utils/js/py_worker.js
My Pyodide initialisation
useAsync
: https://github.com/siraisisatoru/react-markdown-template/blob/fa92e739b3b953695a69158ad2a608f65e6a155f/src/utils/markdownRender.jsx#L227My Pyodide execution: https://github.com/siraisisatoru/react-markdown-template/blob/fa92e739b3b953695a69158ad2a608f65e6a155f/src/utils/codeblock.jsx#L42
The text was updated successfully, but these errors were encountered: