brunoscopelliti / use-did-update

React hook to handle componentDidUpdate lifecycle event.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

use-did-update

GitHub license npm version CircleCI Status Coverage

React hook to handle componentDidUpdate lifecycle event.

The effects run after every completed render - except the initial one - but it's also possible to fire them only when certain values have changed.

Install

npm i @bscop/use-did-update

Usage

import useDidUpdate from "@bscop/use-did-update";

useDidUpdate(
  () => {
    // Executed after each render, but the first one.
    console.log("Yay, it's updated");
  }
);

Api

useDidUpdate(effect, [cleanup], [values]);
  • effect: the side effect.

  • cleanup: clean-up logic to execute in case the component is going to be re-rendered.

  • value: the effect is going to be executed only if also one of these values changed.

Contribute

Read the guidelines.

Run tests

npm test

Coverage

Coverage reports are hosted on codecov.

npm run badge:coverage -- --token=<guid>

Bruno Scopelliti
www.brunoscopelliti.com

About

React hook to handle componentDidUpdate lifecycle event.

License:MIT License


Languages

Language:JavaScript 97.0%Language:Shell 3.0%