Skip to content

Instantly share code, notes, and snippets.

@ljmotta
Created October 13, 2020 19:37
Embed
What would you like to do?
Base64Png Editor Disabled Update Canvas
useEffect(() => {
const ctx = canvasRef.current?.getContext("2d")!;
canvasRef.current!.width = 0;
canvasRef.current!.height = 0;
imageRef.current!.onload = () => {
canvasRef.current!.width = imageRef.current!.width;
canvasRef.current!.height = imageRef.current!.height;
ctx.drawImage(imageRef.current!, 0, 0);
setEditorContent(canvasRef.current!.toDataURL().split(",")[1]);
/**
* When the image finishes to load, the tweakers can properly work
*/
setDisabled(false);
};
return () => {
imageRef.current!.onload = null;
};
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment