@rooks/use-did-update
TypeScript icon, indicating that this package has built-in type declarations

4.11.2 • Public • Published

@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 />);

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @rooks/use-did-update

      Weekly Downloads

      1,237

      Version

      4.11.2

      License

      MIT

      Unpacked Size

      8.71 kB

      Total Files

      14

      Last publish

      Collaborators

      • imbhargav5