DINO
DINO3y ago

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} />;
}
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} />;
}
3 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
DINO
DINOOP3y ago
magic! ✅ !done
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/902647189120118794/1008513227124117634