Server IP : 104.21.14.103 / Your IP : 3.141.28.116 Web Server : LiteSpeed System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : giankuin ( 1871) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/home/giankuin/sieuthiweb.com.vn/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/base/hooks/ |
Upload File : |
/** * External dependencies */ import { useStoreNoticesContext } from '@woocommerce/base-context'; import { useMemo, useRef, useEffect } from '@wordpress/element'; export const useStoreNotices = () => { const { notices, createNotice, removeNotice, createSnackbarNotice, setIsSuppressed, } = useStoreNoticesContext(); // Added to a ref so the surface for notices doesn't change frequently // and thus can be used as dependencies on effects. const currentNotices = useRef( notices ); // Update notices ref whenever they change useEffect( () => { currentNotices.current = notices; }, [ notices ] ); const noticesApi = useMemo( () => ( { hasNoticesOfType: ( type ) => { return currentNotices.current.some( ( notice ) => notice.type === type ); }, removeNotices: ( status = null ) => { currentNotices.current.map( ( notice ) => { if ( status === null || notice.status === status ) { removeNotice( notice.id ); } return true; } ); }, removeNotice, } ), [ removeNotice ] ); const noticeCreators = useMemo( () => ( { addDefaultNotice: ( text, noticeProps = {} ) => void createNotice( 'default', text, { ...noticeProps, } ), addErrorNotice: ( text, noticeProps = {} ) => void createNotice( 'error', text, { ...noticeProps, } ), addWarningNotice: ( text, noticeProps = {} ) => void createNotice( 'warning', text, { ...noticeProps, } ), addInfoNotice: ( text, noticeProps = {} ) => void createNotice( 'info', text, { ...noticeProps, } ), addSuccessNotice: ( text, noticeProps = {} ) => void createNotice( 'success', text, { ...noticeProps, } ), addSnackbarNotice: ( text, noticeProps = {} ) => { createSnackbarNotice( text, noticeProps ); }, } ), [ createNotice, createSnackbarNotice ] ); return { notices, ...noticesApi, ...noticeCreators, setIsSuppressed, }; };