@rooks/use-did-update
v4.11.2
Published
componentDidUpdate hook for react
Downloads
4,185
Maintainers
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!
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 />);