Open aymeric75 opened 1 year ago
Use this way
export const Test = () => {
const canvasRef = useRef(null);
useEffect(() => {
if (canvasRef.current) {
const canvas = canvasRef.current;
const context = canvas.getContext('2d');
context.fillStyle = 'blue';
context.fillRect(0, 0, 100, 100);
}
}, [canvasRef]);
return (
<Canvas ref={canvasRef}/>
)
}
function App() {
return (
<Test />
)
}
This might help https://www.youtube.com/watch?v=wKr1kxNccgo
Hello,
I need to retrieve the context of a canvas, here is what I have tried:
But it gives this error:
ERROR TypeError: canvas.getContext is not a function. (In 'canvas.getContext('2d')', 'canvas.getContext' is undefined)
Any idea where this comes from ?
Thanks