Skip to content

Instantly share code, notes, and snippets.

@richarddprasad
Last active March 26, 2020 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richarddprasad/c049dec1e4c98a566a01013e6b480631 to your computer and use it in GitHub Desktop.
Save richarddprasad/c049dec1e4c98a566a01013e6b480631 to your computer and use it in GitHub Desktop.
React.useEffect(() => {
if (canvasRef.current) {
const renderCtx = canvasRef.current.getContext('2d');
if (renderCtx) {
setContext(renderCtx);
}
}
// Draw a rectangle
if (context) context.fillRect(5, 5, 100, 100);
// Draw a circle
if(context) {
context.beginPath();
context.fillStyle = '#ff7f50';
context.arc(440, 60, 50, 0, Math.PI * 2, true);
context.fill();
context.fillStyle = '#000';
context.closePath();
}
}, [context]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment