JSPM

react-lifecycle-gate

1.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q36386F
  • License ISC

A lightweight component to access lifecycle hooks

Package Exports

  • react-lifecycle-gate

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-lifecycle-gate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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