@darwish/hooks-core
Version:
13 lines (12 loc) • 426 B
JavaScript
import { useEffect } from "react";
import { isFunction, isDev } from "@darwish/utils-is";
import useLatest from "./useLatest";
export default function useUnmount(fn) {
if (isDev && !isFunction(fn)) {
console.error("useUnmount expected parameter is a function, got ".concat(typeof fn));
}
var fnRef = useLatest(fn);
useEffect(function () { return function () {
fnRef.current();
}; }, []);
}