Skip to content
Advertisement

Child component not re-rendering with updated props

I have a child component, it looks through and creates Canvas elements in the DOM, then useEffect() draws things to these Canvases:

JavaScript

And it’s parent component:

JavaScript

When the suer clicks on the Dropdown, I pass the value back up to the parent component (Workspace). This then updates the Workspace state, and I then expect the child coponent to be re-rendered – except it is not. When I look at the logs, I see:

JavaScript

But I dont see:

JavaScript

I only see this log the first time the app runs. The Table component is indeed getting the new updated props, but it wont re-render with this new data. What am I doing wrong?

Advertisement

Answer

useEffect(() => {}, []) replace the componentDidMount in old react versions that means it execute only once after mounting the component in DOM. I am wondering if you really need a useEffect in your case , if it the case you need to use a useEffect without array of dependencies. LIke that:

JavaScript

Solution 2: As i said am wondering if you really need a useEffect you can directly do it like that

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement