UNPKG

@wordpress/block-library

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