@wordpress/block-library
Version:
Block library for the WordPress editor.
54 lines (43 loc) • 1.1 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _element = require("@wordpress/element");
var _data = require("@wordpress/data");
var _notices = require("@wordpress/notices");
/**
* WordPress dependencies
*/
function useNavigationNotice() {
let {
name,
message = ''
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const noticeRef = (0, _element.useRef)();
const {
createWarningNotice,
removeNotice
} = (0, _data.useDispatch)(_notices.store);
const showNotice = customMsg => {
if (noticeRef.current) {
return;
}
noticeRef.current = name;
createWarningNotice(customMsg || message, {
id: noticeRef.current,
type: 'snackbar'
});
};
const hideNotice = () => {
if (!noticeRef.current) {
return;
}
removeNotice(noticeRef.current);
noticeRef.current = null;
};
return [showNotice, hideNotice];
}
var _default = useNavigationNotice;
exports.default = _default;
//# sourceMappingURL=use-navigation-notice.js.map
;