monsterooo / blog

and make promises by the hours
MIT License
14 stars 1 forks source link

recompose shouldUpdate #22

Open monsterooo opened 6 years ago

monsterooo commented 6 years ago

shouldUpdate 介绍

shouldUpdateReact shouldUpdate的高阶函数包装,用法同https://reactjs.org/docs/react-component.html#shouldcomponentupdate一样。

shouldUpdate Flow Type

shouldUpdate(
  test: (props: Object, nextProps: Object) => boolean
): HigherOrderComponent

shouldUpdate 例子

const Foo = compose(
  pure,
  shouldUpdate((props, nextProps) => props.title !== nextProps.title) ,
)(({ title }) => (
  <div>{console.log('render')}{title}</div>
))

在线DEMO

codepen在线预览