@wordpress/block-library
Version:
Block library for the WordPress editor.
44 lines (37 loc) • 953 B
JavaScript
/**
* WordPress dependencies
*/
import { useRef } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { store as noticeStore } from '@wordpress/notices';
function useNavigationNotice() {
let {
name,
message = ''
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const noticeRef = useRef();
const {
createWarningNotice,
removeNotice
} = useDispatch(noticeStore);
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];
}
export default useNavigationNotice;
//# sourceMappingURL=use-navigation-notice.js.map