monsterooo / blog

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

recompose withProps #8

Open monsterooo opened 6 years ago

monsterooo commented 6 years ago

withProps介绍

withProps接受一个函数参数,这个函数参数会返回一个对象用作为接下来的组件的props。与mapProps不同的是,除了withProps函数参数返回的props外,组件接收到的其他参数也将一起被传递

withProps Flow Type

withProps(
  createProps: (ownerProps: Object) => Object | Object
): HigherOrderComponent

withProps实例

const ListMap = withProps(({ list }) => {
  return {
    list: list.map((e) => e + '_withProps')
  };
})(List);
// title 也会被一同传递到List组件中
<ListMap list={Item} title="我是一个标题文本!" />

在线DEMO

codepen在线预览