@wordpress/commands
Version:
Handles the commands menu.
43 lines (39 loc) • 1.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = useCommandContext;
var _element = require("@wordpress/element");
var _data = require("@wordpress/data");
var _store = require("../store");
var _lockUnlock = require("../lock-unlock");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Sets the active context of the command palette
*
* @param {string} context Context to set.
*/
function useCommandContext(context) {
const {
getContext
} = (0, _data.useSelect)(_store.store);
const initialContext = (0, _element.useRef)(getContext());
const {
setContext
} = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
(0, _element.useEffect)(() => {
setContext(context);
}, [context, setContext]);
// This effects ensures that on unmount, we restore the context
// that was set before the component actually mounts.
(0, _element.useEffect)(() => {
const initialContextRef = initialContext.current;
return () => setContext(initialContextRef);
}, [setContext]);
}
//# sourceMappingURL=use-command-context.js.map
;