Files
outline/app/hooks/useUnmount.ts
Tom Moor 084490ba6b chore: Remove React in scope requirement (#9261)
* Add rules

* codemod: update-react-imports

* Update babelrc
2025-05-20 19:26:11 -04:00

21 lines
405 B
TypeScript

import { useRef, useEffect } from "react";
/**
* Hook that executes a callback when the component unmounts.
*
* @param callback Function to be called on component unmount
*/
const useUnmount = (callback: (...args: Array<any>) => any) => {
const ref = useRef(callback);
ref.current = callback;
useEffect(
() => () => {
ref.current();
},
[]
);
};
export default useUnmount;