DINOD
Reactiflux4y ago
5 replies
DINO

DINO – 23-11 Aug 14

How do I solve this error:
Type 'MutableRefObject<HTMLCanvasElement | undefined>' is not assignable to type 'LegacyRef<HTMLCanvasElement> | undefined'.
. This is my code:
function Canvas({
  draw,
  width,
  height,
}: {
  draw: (context: any) => {};
  width: number;
  height: number;
}) {
  const canvas = useRef<HTMLCanvasElement>();

  useEffect(() => {
    if (canvas.current) {
      const context = canvas.current.getContext("2d");
      draw(context);
    }
  });

  return <canvas ref={canvas} width={width} height={height} />;
}
Was this page helpful?