@wordpress/hooks
Version:
WordPress hooks library.
26 lines (25 loc) • 922 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
/**
* 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 {import('.').Hooks} hooks Hooks instance.
* @param {import('.').StoreKey} storeKey
*
* @return {() => string | null} 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
;