简体   繁体   English

组件更新生命周期ReactJS

[英]Component update lifecycle ReactJS

Stuck with one problem. 卡在一个问题上。

I have parent component for example <Parent /> . 我有例如<Parent />父组件。 In render method of this parent component i'm rendering cards for example <CardItem /> . 在此父组件的render方法中,我正在渲染卡片 ,例如<CardItem />

And in this <CardItem /> component i have <IconComponent/> . 在这个<CardItem />组件中,我有<IconComponent/>

So the main problem is: 因此,主要问题是:
When i'm trying to use componentWillUpdate / did in <IconComponent/> i see props for all components. 当我尝试在<IconComponent/>使用componentWillUpdate / did ,我看到了所有组件的道具。

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. 例如,我将渲染5个<CardItem />组件,一旦更新5个组件之一,我的控制台日志中将有5行。

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. 我认为最好的解决方案可以使用componentWillReceiveProps(nextProps)因为它将为您提供新的Props作为该组件,然后可以执行您想要的任何操作。 for more detail check react lifecycle 有关更多详细信息,请检查反应生命周期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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