@wordpress/commands
Version:
Handles the commands menu.
22 lines (21 loc) • 766 B
JavaScript
// packages/commands/src/hooks/use-command-context.js
import { useEffect, useRef } from "@wordpress/element";
import { useDispatch, useSelect } from "@wordpress/data";
import { store as commandsStore } from "../store";
import { unlock } from "../lock-unlock";
function useCommandContext(context) {
const { getContext } = useSelect(commandsStore);
const initialContext = useRef(getContext());
const { setContext } = unlock(useDispatch(commandsStore));
useEffect(() => {
setContext(context);
}, [context, setContext]);
useEffect(() => {
const initialContextRef = initialContext.current;
return () => setContext(initialContextRef);
}, [setContext]);
}
export {
useCommandContext as default
};
//# sourceMappingURL=use-command-context.js.map