mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
21 lines
387 B
TypeScript
21 lines
387 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: () => void) => {
|
|
const ref = useRef(callback);
|
|
ref.current = callback;
|
|
|
|
useEffect(
|
|
() => () => {
|
|
ref.current();
|
|
},
|
|
[]
|
|
);
|
|
};
|
|
|
|
export default useUnmount;
|