简体   繁体   中英

How to call a method once a component is rendered?

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]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM