Open monsterooo opened 6 years ago
onlyUpdateForKeys接收一个数组字符串,只有当指定的props被修改时才更新。这个api不像shouldUpdate不用自己写比较逻辑,它的内部会自动使用shouldUpdate和shallowEqual进行包装。
onlyUpdateForKeys
props
shouldUpdate
shallowEqual
onlyUpdateForKeys( propKeys: Array<string> ): HigherOrderComponent
const { compose, pure, onlyUpdateForKeys } = Recompose; // 只有当 title props 被更改时才会更新组件(render) const Foo = compose( pure, onlyUpdateForKeys(['title']) , )(({ title }) => ( <div>{console.log('render')}{title}</div> ))
在codepen在线预览
onlyUpdateForKeys 介绍
onlyUpdateForKeys
接收一个数组字符串,只有当指定的props
被修改时才更新。这个api不像shouldUpdate
不用自己写比较逻辑,它的内部会自动使用shouldUpdate
和shallowEqual
进行包装。onlyUpdateForKeys Flow Type
onlyUpdateForKeys 实例
在线DEMO
在codepen在线预览