useDidUpdate
Aboutβ
componentDidUpdate hook for react
Installationβ
npm install --save rooks
Importing the hookβ
import { useDidUpdate } from "rooks";
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 />);
Codesandbox Examplesβ
Basic Usageβ
Join Bhargav's discord serverβ
You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.