Reputation: 31
I have a parent component which passdown an array prop to a child component. but as render runs before componentDidMount ,where I am setting the value to that array.. the child component recieve an empty array as prop.
I searched on net ,it seems componentWillRecieveProps Can help wiyh making child component to rr render.. but as this method is deprecated in react 16 and further. What should be the goto way of doing it.
Upvotes: 0
Views: 22
Reputation: 11247
Only call the child component when the props value has been populated like
this.state.arrayProp.length && <ChildComponent />
Now when you have populated arrayProp array state in componentDidMount
, render method will again be called after componentDidMount
, So, now ChildComponent
will be called with correctly populated array value.
Hope that helps!!!
Upvotes: 1