Skip to content

Latest commit

 

History

History
34 lines (30 loc) · 878 Bytes

withLifecycle.md

File metadata and controls

34 lines (30 loc) · 878 Bytes

withLifecycle

Description

Adds lifecycle hooks to the base component. The full API list can be found here. Please note that Inferno itself offers lifecycle hooks for functional components as described in the docs. The difference is, that this hook can be used INSIDE the component and not from the parent component.

API

withLifecycle(
  hooks : Object,
) : Function;

Example

import {
  compose,
  withLifecycle
} from 'incompose';

const Counter = (props) => (
  <div>
    <h1>component with lifecycle</h1>
  </div>
);

export default compose(
  withLifecycle({
    componentDidMount     : (el) => console.warn('mounted'),
    componentWillUnmount  : () => console.warn('will unmount'),
    componentShouldUpdate : (props, nextProps)  => true, // on false, component won't update
  }),
)(Counter);