您可以这样做而不必
componentWillReceiveProps
就这样:
export class Styles extends Component {
isDirtyTwo = false;
isDirtyThree = false;
..
componentDidUpdate(prevProps) {
this.isDirtyTwo = this.isDirtyTwo || !isEqual(prevProps.two, this.props.two);
this.isDirtyThree = this.isDirtyThree || !isEqual(prevProps.three, this.props.three);
if (!_.isEmpty(this.props.one) && this.isDirtyTwo && this.isDirtyThree) {
this.isDirtyTwo = false;
this.isDirtyThree = false;
this.myMethod();
}
}
..
}
这会叫
myMethod
什么时候
one
是空的,并且在某个时刻其他两个道具都已更改。(我假设有一次
一
如果为空,则保持不变,但如果不为空,则可以为它添加其他属性。)