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
Usage
Import the hook from @abhushanaj/react-hooks
and use in required component;
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
Parameter | Type | Description | Default |
---|---|---|---|
callback | ()=>void | The callback function to run after component unmount. | N/A |