1import useUnmount from "@repo/ui/hooks/use-unmount";
1useUnmount(() => {
2 console.log("Component unmounted");
3});
1import { useEffect, useRef } from "react";
2
3function useUnmount(func: () => void) {
4 const funcRef = useRef(func);
5
6 funcRef.current = func;
7
8 useEffect(
9 () => () => {
10 funcRef.current();
11 },
12 []
13 );
14}
15
16export default useUnmount;