Skip to main content
Version: v3.6.0

@rooks/use-did-update

componentDidUpdate hook for react

Build Status

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