react-lifecycle-gate

1.1.2 • Public • Published

react-lifecycle-gate

A lightweight component to which lifecycle hooks can easily be attached as props. Similar to react-lifecycle-component but slightly simpler

npm i react-lifecycle-gate --save

Usage

Suppose you want to use a pure functional component, and need to trigger some stuffs on e.g. componentDidMount, just wrap your content in a lifecycle gate and you're done.

import LifecycleGate from 'react-lifecycle-gate';

const initStuffs = () => {};

export const JankyComponent = props => (
  <LifecycleGate
    willMount={initStuffs}
    willUpdate={() => {
      console.log('fresh props just arrived');
    }} >
    <p>Children get rendered if included. If not, the callbacks get called anyways of course</p>
  </LifecycleGate>
);

Supported properties

willMount

didMount

willUnmount

willReceiveProps

willUpdate

didUpdate

Dependencies (0)

    Dev Dependencies (7)

    Package Sidebar

    Install

    npm i react-lifecycle-gate

    Weekly Downloads

    1

    Version

    1.1.2

    License

    ISC

    Unpacked Size

    6.44 kB

    Total Files

    7

    Last publish

    Collaborators

    • fresidue