问题描述
之前看到同事写的组件里componentWillReceiveProps方法里做了判断如下 想知道到底有没有必要 记得父组件更新会导致子组件componentWillReceiveProps和shouldComponentUpdate一定触发 所以即使在componentWillReceiveProps里判断了不setState也会触发shouldComponentUpdate的 不知道我的理解对不对 望大神解答到底有没有必要写这一层判断
类似代码
if (this.props.x !== nextProps.x) {
this.setState({...})
}
自己搜了下文档 结论如下 希望之后有大佬看到错误处指正