简体   繁体   中英

Component update lifecycle ReactJS

Stuck with one problem.

I have parent component for example <Parent /> . In render method of this parent component i'm rendering cards for example <CardItem /> .

And in this <CardItem /> component i have <IconComponent/> .

So the main problem is:
When i'm trying to use componentWillUpdate / did in <IconComponent/> i see props for all components.

For example I will render 5 <CardItem /> components and once one of 5 components updated i will have 5 line's in my console log.

Question : How to catch only one component which was updated?

I think the best solution can use componentWillReceiveProps(nextProps) as will be giving you the new Props as that component and can then do whatever ever you want. for more detail check react lifecycle

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