Skip to content

useOnUnmount

Run a callback after a component unmounts using the useOnUnmount hook.

The useOnUnmount hook is helpful when you want to run a callback function after the component has unmounted. It relies on the React.useEffect() hook internally.

useOnUnmount

Unmounted: 0 time

Try mounting and unmounting the component and see the status of count update.Check console for unmount message

Usage

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

./src/App.tsx
import { useOnUnmount } from '@abhushanaj/react-hooks';
function App() {
useOnUnmount(() => {
console.log('Unmounted!');
});
return (
<div>
<p>I am now mounted!</p>
</div>
);
}
export default App;

API Reference

Parameters

ParameterTypeDescriptionDefault
callback()=>voidThe callback function to run after component unmount.N/A