11"use client" ;
22
3- import { ReactNode , RefObject , useEffect , useRef } from "react" ;
3+ import { ReactNode , useEffect } from "react" ;
44import { RuntimeContext } from "./interface" ;
55import { RuntimeLang } from "./languages" ;
66import { TypeScriptProvider , useTypeScript } from "./typescript/runtime" ;
@@ -12,14 +12,14 @@ import { WorkerProvider } from "./worker/runtime";
1212
1313export function useRuntime ( language : RuntimeLang ) : RuntimeContext {
1414 const runtimes = useRuntimeAll ( ) ;
15- const runtime = runtimes . current [ language ] ;
15+ const runtime = runtimes [ language ] ;
1616 const { init } = runtime ;
1717 useEffect ( ( ) => {
1818 init ?.( ) ;
1919 } , [ init ] ) ;
2020 return runtime ;
2121}
22- export function useRuntimeAll ( ) : RefObject < Record < RuntimeLang , RuntimeContext > > {
22+ export function useRuntimeAll ( ) : Record < RuntimeLang , RuntimeContext > {
2323 // すべての言語のcontextをインスタンス化
2424 const pyodide = usePyodide ( ) ;
2525 const ruby = useRuby ( ) ;
@@ -28,16 +28,15 @@ export function useRuntimeAll(): RefObject<Record<RuntimeLang, RuntimeContext>>
2828 const wandboxCpp = useWandbox ( "cpp" ) ;
2929 const wandboxRust = useWandbox ( "rust" ) ;
3030
31- const runtimes = useRef < Record < RuntimeLang , RuntimeContext > > ( { } as never ) ;
32- runtimes . current . python = pyodide ;
33- runtimes . current . ruby = ruby ;
34- runtimes . current . javascript = jsEval ;
35- runtimes . current . typescript = typescript ;
36- runtimes . current . cpp = wandboxCpp ;
37- runtimes . current . rust = wandboxRust ;
38-
3931 // initはしない。呼び出し側でする必要がある
40- return runtimes ;
32+ return {
33+ python : pyodide ,
34+ ruby : ruby ,
35+ javascript : jsEval ,
36+ typescript : typescript ,
37+ cpp : wandboxCpp ,
38+ rust : wandboxRust ,
39+ } ;
4140}
4241export function RuntimeProvider ( { children } : { children : ReactNode } ) {
4342 return (
0 commit comments