How to call a method once a component is rendered?

Tags: , , ,

I have a parent component that conditionally renders two components. Once I am done entering data in the first component, I click done and then render the second component. I want the second component to only then parse all the data I entered in the first component.

Im a little confused which lifecycle method I am supposed to be using.

componentdidupdate will not be called unless the state of the second component is updated, correct? And componentdidmount will be called before I have finished entering data into the first component, since it is already inserted into the tree (although not rendered yet conditionally)?


You can use a the useEffect and set the component as a dependency.

useEffect(() => {
}, [yourcomponentStateValue]);

Source: stackoverflow