import {useEffect, useRef} from "react"; interface Props { renderFn: (ImageData) => void } export const Canvas: React.FC = ({renderFn}: Props) => { const canvasRef = useRef(null); useEffect(() => { const ctx = canvasRef.current?.getContext("2d"); if (!ctx) { console.log("Canvas not ready"); } const image = ctx.createImageData(canvasRef.current.width, canvasRef.current.height); renderFn(image); ctx.putImageData(image, 0, 0); }, []); return ( ); }; export default Canvas;