import React from "react"; import { LanguageProvider } from "../languages/types"; export interface RendererRef { /** Update runtime state to renderer */ updateState: (state: RS | null) => void; } /** * React component that acts as an imperatively controller wrapper * around the actual language renderer. This is to pull renderer state updates * outside of Mainframe for performance reasons. */ const RendererWrapperComponent = ( { renderer }: { renderer: LanguageProvider["Renderer"] }, ref: React.Ref> ) => { const [state, setState] = React.useState(null); React.useImperativeHandle(ref, () => ({ updateState: setState, })); return renderer({ state }); }; export const RendererWrapper = React.forwardRef(RendererWrapperComponent);