UNPKG

rooks

Version:

Essential React custom hooks ⚓ to super charge your components!

39 lines (38 loc) 1.54 kB
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import { useDidMount } from "./useDidMount"; import { useDidUpdate } from "./useDidUpdate"; import { useWillUnmount } from "./useWillUnmount"; /** * useLifecycleLogger hook * logs parameters as component transitions through lifecycles * * @param componentName Name of the component * @param {...*} otherArgs Other arguments to log * @see https://react-hooks.org/docs/useLifecycleLogger */ var useLifecycleLogger = function (componentName) { if (componentName === void 0) { componentName = "Component"; } var otherArgs = []; for (var _i = 1; _i < arguments.length; _i++) { otherArgs[_i - 1] = arguments[_i]; } useDidMount(function () { console.log.apply(console, __spreadArray(["".concat(componentName, " mounted")], otherArgs, false)); return function () { return console.log("".concat(componentName, " unmounted")); }; }); useDidUpdate(function () { console.log.apply(console, __spreadArray(["".concat(componentName, " updated")], otherArgs, false)); }); useWillUnmount(function () { console.log("".concat(componentName, " unmounted")); }); }; export { useLifecycleLogger };