How can we fix my ReactJS canvas resize prototype? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How can we fix my ReactJS canvas resize prototype?

I'm trying to make a fairly simple ReactJS component that dynamically sets width and height to match the canvas DOM element's pixel dimensions but running into a problem. I wrote it as short and simple as possible to help anyone reading this question. Here is my prototype: All of my custom JavaScript is in: When I check the console, my console.log statements show: render called. canvasWidth = 100, canvasHeight = 100 reactApp.js:8 componentDidMount called. canvasWidth = 100, canvasHeight = 100 reactApp.js:19 Tried setting state to {"canvasWidth":895,"canvasHeight":696} reactApp.js:42 render called. canvasWidth = 895, canvasHeight = 696 How can I get my drawing code to run after the correct canvasWidth and canvasHeight have been processed by the render method?

13th Jul 2021, 2:56 AM
Josh Greig
Josh Greig - avatar
1 Answer
You could try an approach with promises, or you can try to use state and props updates. I currently only have my phone with me, I can look at the code in 2 weeks, then I can use my Computer to inspect the Code. (If the problem isn't solved by then)
27th Aug 2021, 4:30 PM
Knäcke Brot
Knäcke Brot - avatar