2016-09-14 44 views
0

在下图中,我们对生命周期方法进行了反应。 有没有其他方法只会在我们改变状态时才会调用?Reactjs生命周期:只在更改状态时调用

这里shouldComponentUpdate & comonentWillUpdate都会在更改为道具和状态的情况下调用。

谢谢您提前!

enter image description here

+0

我不认为有这样的钩目前。你为什么需要这个? – berrtech

回答

1

没有生命周期的方法,但你可以使用现有的shouldComponentUpdatecomponentWillUpdate挂钩和包装你的状态变化逻辑检查,以确保previousState !== this.state

0

当你改变你的状态,shouldComponentUpdate会被称为,如果这种方法return false。没有其他生命周期方法会再被调用。 因此,如果您不想要调用其他生命周期方法,那么只需在shouldComponentUpdate中检查return false