mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
14 lines
337 B
TypeScript
14 lines
337 B
TypeScript
import { useRef } from 'react';
|
|
import useEffectOnce from './useEffectOnce';
|
|
|
|
const useUnmount = (fn: () => any): void => {
|
|
const fnRef = useRef(fn);
|
|
|
|
// update the ref each render so if it change the newest callback will be invoked
|
|
fnRef.current = fn;
|
|
|
|
useEffectOnce(() => () => fnRef.current());
|
|
};
|
|
|
|
export default useUnmount;
|