@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
33 lines (32 loc) • 838 B
JavaScript
// packages/widget-dashboard/src/components/commands/use-pending-when-edit-mode.ts
import { useCallback, useEffect, useRef } from "@wordpress/element";
function usePendingWhenEditMode({
editMode,
onEditChange
}) {
const pendingRef = useRef(null);
const wasEditingRef = useRef(editMode);
useEffect(() => {
if (!wasEditingRef.current && editMode && pendingRef.current) {
const action = pendingRef.current;
pendingRef.current = null;
action();
}
wasEditingRef.current = editMode;
}, [editMode]);
return useCallback(
(action) => {
if (editMode) {
action();
return;
}
pendingRef.current = action;
onEditChange?.(true);
},
[editMode, onEditChange]
);
}
export {
usePendingWhenEditMode
};
//# sourceMappingURL=use-pending-when-edit-mode.mjs.map