UNPKG

@wordpress/block-library

Version:
35 lines (34 loc) 1.11 kB
// packages/block-library/src/navigation/edit/use-navigation-notice.js import { useCallback, useRef } from "@wordpress/element"; import { useDispatch } from "@wordpress/data"; import { store as noticeStore } from "@wordpress/notices"; function useNavigationNotice({ name, message = "" } = {}) { const noticeRef = useRef(); const { createWarningNotice, removeNotice } = useDispatch(noticeStore); const showNotice = useCallback( (customMsg) => { if (noticeRef.current) { return; } noticeRef.current = name; createWarningNotice(customMsg || message, { id: noticeRef.current, type: "snackbar" }); }, [noticeRef, createWarningNotice, message, name] ); const hideNotice = useCallback(() => { if (!noticeRef.current) { return; } removeNotice(noticeRef.current); noticeRef.current = null; }, [noticeRef, removeNotice]); return [showNotice, hideNotice]; } var use_navigation_notice_default = useNavigationNotice; export { use_navigation_notice_default as default }; //# sourceMappingURL=use-navigation-notice.js.map