UNPKG

rc-hooks

Version:
18 lines (17 loc) 491 B
import { useEffect } from 'react'; import useLatest from '../useLatest'; /** * 只在组件 `unmount` 时执行的 Hook。 * * @param fn 组件 `unmount` 时执行的函数。 * @example * useUnmount(() => { * console.log('unmount'); * }); */ var useUnmount = function (fn) { var fnRef = useLatest(fn); // eslint-disable-next-line react-hooks/exhaustive-deps useEffect(function () { return function () { return fnRef.current(); }; }, []); }; export default useUnmount;