react-component-debounce
react-component-debounce copied to clipboard
感觉 shouldUpdate 存在豪无意义
先赞,深度好文
不过我感觉 ReactFormFieldDebounce
里 componentWillReceiveProps
方法的条件判断似乎可以省略了
if (shouldUpdate([theOptions.valuePropName], this.props, nextProps)) {
if (this.lastValue !== nextProps[theOptions.valuePropName]) {
this.valueUpdateDebounce(nextProps[theOptions.valuePropName]);
}
}
因为你的 shouldUpdate
实现是对比遍历 this.props
和 nextProps
,似乎可以交给react自己的diff,效果也一样吧?
去掉上面两个if判断,直接使用 this.valueUpdateDebounce
,即便最坏的情况,最多也就影响一个表单域的性能
同样,shouldComponentUpdate
里的 shouldUpdate
也意义不大吧?