withProps
接受一个函数参数,这个函数参数会返回一个对象用做为接下来的组件的props
。与mapProps
不一样的是,除了withProps
函数参数返回的props
外,组件接收到的其余参数也将一块儿被传递git
withProps(
createProps: (ownerProps: Object) => Object | Object
): HigherOrderComponent
复制代码
const ListMap = withProps(({ list }) => {
return {
list: list.map((e) => e + '_withProps')
};
})(List);
// title 也会被一同传递到List组件中
<ListMap list={Item} title="我是一个标题文本!" />
复制代码
在codepen在线预览github
我至少每周会更新4个左右的api使用指南,欢迎关注api