@wordpress/block-library
Version:
Block library for the WordPress editor.
33 lines (32 loc) • 1.13 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_element = require("@wordpress/element");
let _wordpress_data = require("@wordpress/data");
let _wordpress_notices = require("@wordpress/notices");
// packages/block-library/src/navigation/edit/use-navigation-notice.js
function useNavigationNotice({ name, message = "" } = {}) {
const noticeRef = (0, _wordpress_element.useRef)();
const { createWarningNotice, removeNotice } = (0, _wordpress_data.useDispatch)(_wordpress_notices.store);
return [(0, _wordpress_element.useCallback)((customMsg) => {
if (noticeRef.current) return;
noticeRef.current = name;
createWarningNotice(customMsg || message, {
id: noticeRef.current,
type: "snackbar"
});
}, [
noticeRef,
createWarningNotice,
message,
name
]), (0, _wordpress_element.useCallback)(() => {
if (!noticeRef.current) return;
removeNotice(noticeRef.current);
noticeRef.current = null;
}, [noticeRef, removeNotice])];
}
exports.default = useNavigationNotice;
//# sourceMappingURL=use-navigation-notice.cjs.map