Skip to content

useOnUpdate

Runs a callback on every component update or re-render.

The useOnUpdate hook is helpful when you want to run a callback each time a component updates or re-renderes. The callback won’t be invoked during component mount and unmount.

For mount and unmount you can use the useOnMount and useOnUnmount hook respectively.

useOnUpdate

Count Value is : 0

Check console for update messages.

Usage

Import the hook from @abhushanaj/react-hooks and use in required component;

./src/App.tsx
import { useOnUpdate } from '@abhushanaj/react-hooks';
function App() {
useOnUpdate(() => {
console.log('I am run on every re-render');
}, shouldRun);
return (
<div>
<p>Callback is run every time component re-renders/updates.</p>
</div>
);
}
export default App;

API Reference

Parameters

ParameterTypeDescriptionDefault
callback()=>voidThe callback function to run after component update/re-render.N/A