import { useEffect, useRef } from "react"; import type { NonDeletedSceneElementsMap } from "../../element/types"; import type { AppState } from "../../types"; import type { RenderableElementsMap, StaticCanvasRenderConfig, } from "../../scene/types"; import type { RoughCanvas } from "roughjs/bin/canvas"; import { renderNewElementScene } from "../../renderer/renderNewElementScene"; import { isRenderThrottlingEnabled } from "../../reactUtils"; interface NewElementCanvasProps { appState: AppState; elementsMap: RenderableElementsMap; allElementsMap: NonDeletedSceneElementsMap; scale: number; rc: RoughCanvas; renderConfig: StaticCanvasRenderConfig; } const NewElementCanvas = (props: NewElementCanvasProps) => { const canvasRef = useRef(null); useEffect(() => { if (!canvasRef.current) { return; } renderNewElementScene( { canvas: canvasRef.current, scale: props.scale, newElement: props.appState.newElement, elementsMap: props.elementsMap, allElementsMap: props.allElementsMap, rc: props.rc, renderConfig: props.renderConfig, appState: props.appState, }, isRenderThrottlingEnabled(), ); }); return ( ); }; export default NewElementCanvas;