UNPKG

@wordpress/hooks

Version:
30 lines (28 loc) 888 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; /** * Internal dependencies */ /** * Returns a function which, when invoked, will return the name of the * currently running hook, or `null` if no hook of the given type is currently * running. * * @param hooks Hooks instance. * @param storeKey * * @return Function that returns the current hook name or null. */ function createCurrentHook(hooks, storeKey) { return function currentHook() { var _currentArray$at$name; const hooksStore = hooks[storeKey]; const currentArray = Array.from(hooksStore.__current); return (_currentArray$at$name = currentArray.at(-1)?.name) !== null && _currentArray$at$name !== void 0 ? _currentArray$at$name : null; }; } var _default = exports.default = createCurrentHook; //# sourceMappingURL=createCurrentHook.js.map