Reactjs 不安全的组件将始终接收触发每个输入值更改的Props

Reactjs 不安全的组件将始终接收触发每个输入值更改的Props,reactjs,antd,Reactjs,Antd,UNSAFE_componentWillReceiveProps始终会为组件本身中的每个输入值更改触发 据我所知,只能根据父组件的道具值变化触发 有人能给我一个提示吗?如果我的理解有误,请纠正我。来自: 使用此生命周期方法通常会导致错误和不一致 改用componentdiddupdate: componentDidUpdate(prevProps, prevState) { if (this.props.someProp != prevProps.someProp) { // The

UNSAFE_componentWillReceiveProps始终会为组件本身中的每个输入值更改触发

据我所知,只能根据父组件的道具值变化触发

有人能给我一个提示吗?如果我的理解有误,请纠正我。

来自:

使用此生命周期方法通常会导致错误和不一致

改用
componentdiddupdate

componentDidUpdate(prevProps, prevState) {
  if (this.props.someProp != prevProps.someProp) {
    // The property someProp changed
    // Do something in response
  }
}

componentWillReceiveProps采用如下参数:

 componentWillReceiveProps(props){
 const {someprop} : this.props;
 if(someprop !== props.someprop){
 //do whatever you want with the refreshed someprop
 }
 }

是的,你的理解是错误的。检查道具是否更改是
nextrops
param的作用。最好使用其他钩子,因为这个钩子是遗留的,可能会导致不良行为。一个更好的钩子取决于你的情况。考虑一下解释吧。