@rooks/use-did-update

componentDidUpdate hook for react

Usage no npm install needed!

<script type="module">
  import rooksUseDidUpdate from 'https://cdn.skypack.dev/@rooks/use-did-update';
</script>

README

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