@ducor/hooks
Version:
A collection of useful React hooks for building modern web applications. Includes hooks for clipboard operations, window events, intervals, timeouts, and more.
15 lines (14 loc) • 399 B
JavaScript
import { useEffect } from "react";
/**
* `useUnmountEffect` runs the provided callback function when the component unmounts.
*
* @param fn - The function to execute on unmount.
*/
const useUnmountEffect = (fn) => {
useEffect(() => {
return () => {
fn();
};
}, []); // Empty dependency array ensures it only runs on unmount
};
export default useUnmountEffect;