Skip to content

Instantly share code, notes, and snippets.

@richarddprasad
Created March 26, 2020 16:44
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/b98a89e014441acb59d4f77944dbb021 to your computer and use it in GitHub Desktop.
Save richarddprasad/b98a89e014441acb59d4f77944dbb021 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);
}, [context]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment