Last active
March 26, 2020 17:01
-
-
Save richarddprasad/c049dec1e4c98a566a01013e6b480631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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