monsterooo / blog

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

recompose lifecycle #26

Open monsterooo opened 6 years ago

monsterooo commented 6 years ago

lifecycle 介绍

lifecycleReact Component API的高阶函数版本,通过它可以覆盖React原来的方法除了render函数外。

lifecycle Flow Type

lifecycle(
  spec: Object,
): HigherOrderComponent

lifecycle 例子

const { compose, pure, lifecycle } = Recompose;

const Foo = compose(
  pure,
  lifecycle({
    componentDidMount() {
      alert('组件已被加载');
    }
  }),
)(() => (
  <div>Hello,World!</div>
));

在线DEMO

codepen在线预览