-2
我在componentWillReceiveProps
中调用函数来更新函数中的状态,但状态没有变化。如何运行componentwillmount生命周期onclick?
有没有办法通过调用componentWillReceiveProps
来更新状态?
我在componentWillReceiveProps
中调用函数来更新函数中的状态,但状态没有变化。如何运行componentwillmount生命周期onclick?
有没有办法通过调用componentWillReceiveProps
来更新状态?
componentWillReceiveProps触发的唯一方法是组件的道具更改时。在此方法中,您应该将当前的道具与新道具进行比较,并相应地设置您的状态。 setState通常不会触发此函数,并且在组件的初始安装时不会触发它。
Ref:https://facebook.github.io/react/docs/react-component.html#componentwillreceiveprops