frontend / features/CodeRunner/useCodeRunner / useCodeRunner
Function: useCodeRunner()
useCodeRunner():
object
Defined in: features/CodeRunner/useCodeRunner.ts:28
Hook which manages code execution state and gives access to worker client.
Creates PyodideWorkerClient on mount and disposes it on unmount. Because client lives inside hook, all components which need to talk to worker should get clientRef from this hook and pass it down — this way single worker is shared between code runner, debugger and file manager.
Returns
object
output— accumulated stdout and error messages from worker.isReady—trueafter Pyodide finished initialization.isRunning—truewhile code is running (not debug).runCode(code, inputFilenames?, stdinText?)— starts execution.stopCode()— sends stop signal to worker.clearCodeOutput()— wipes output without touching worker.clientRef— ref to worker client, should be passed to other hooks.
clearCodeOutput
clearCodeOutput: () =>
void
Returns
void
clientRef
clientRef:
RefObject<PyodideWorkerClient|null>
isReady
isReady:
boolean
isRunning
isRunning:
boolean
output
output:
string
runCode
runCode: (
code,inputFilenames,stdinText) =>Promise<void>
Parameters
code
string
inputFilenames?
string[] = []
stdinText?
string = ''
Returns
Promise<void>
stopCode
stopCode: () =>
void
Returns
void
Example
tsx
const { output, runCode, clientRef } = useCodeRunner();
const files = useInputOutputFiles(clientRef);