etc-hooks
Version:
Etcetera React 业务 Hooks
23 lines (22 loc) • 736 B
JavaScript
function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
import { useEffect } from "react";
import useLatest from "../useLatest";
import { isFunction } from "../utils";
import isDev from "../utils/isDev";
var useUnmount = function useUnmount(fn) {
if (isDev) {
if (!isFunction(fn)) {
console.error("useUnmount expected parameter is a function, but got ".concat(typeof fn === "undefined" ? "undefined" : _type_of(fn)));
}
}
var fnRef = useLatest(fn);
useEffect(function() {
return function() {
return fnRef.current();
};
}, []);
};
export default useUnmount;