@rooks/use-did-update

v4.11.2
componentDidUpdate hook for react
use did update componentDidUpdate react hooks rooks react-hooks.org

@rooks/use-did-update

Note: Future updates to this package have moved to the main package rooks. All hooks now reside in a single package which you can install using

npm install rooks

or

yarn add rooks

Rooks is completely treeshakeable and if you use only 1 of the 50+ hooks in the package, only that hook will be bundled with your code. Your bundle will only contain the hooks that you need. Cheers!

TitleCard

Build Status

About

componentDidUpdate hook for react

Installation

npm install --save @rooks/use-did-update

Importing the hook

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

Usage

function Demo() {
  const [value, setValue] = useState(0);
  const [hasUpdated, setHasUpdated] = useState(false);
  useDidUpdate(() => {
    console.log("Update");
    setHasUpdated(true);
  }, [value]);
  return (
    <>
      <button onClick={() => setValue(value + 1)}>Value is {value}</button>
      <p>Has updated - {hasUpdated.toString()}</p>
      <p>Please check the console for logs.</p>
    </>
  );
}

render(<Demo />);
npm i @rooks/use-did-update

Metadata

  • MIT
  • Whatever
  • Unknown
  • released 5/1/2021

Downloads

Maintainers