monsterooo / blog

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

recompose renameProp renameProps #13

Open monsterooo opened 6 years ago

monsterooo commented 6 years ago

renameProp renameProps 介绍

renameProp renameProps 可以改变指定props的名字,它们的功能类似,renameProp接收两个参数第一个参数为老的props第二个参数为命名后的propsrenameProps接收一个对象,其key值为老的propsvalue为命名后的props

renameProp Flow Type

renameProp(
  oldName: string,
  newName: string
): HigherOrderComponent

renameProps Flow Type

renameProps(
  nameMap: { [key: string]: string }
): HigherOrderComponent

renameProp renameProps 实例

const { compose, renameProp, renameProps } = Recompose;
const Foo = compose(
  renameProp('title', 'headline'),
  renameProps({ desc: 'description', age: 'old' }),
)(({ headline, description, old }) => ([
  <div>{headline}</div>,
  <div>{description}{old}</div>
]))

在线DEMO

codepen在线预览