Server IP : 172.67.158.161 / Your IP : 3.142.134.23 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 : /home/giankuin/www/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/hocs/ |
Upload File : |
/** * External dependencies */ import { useRef } from '@wordpress/element'; import { getSetting } from '@woocommerce/settings'; import { CART_STORE_KEY } from '@woocommerce/block-data'; import { useSelect } from '@wordpress/data'; /** * Hydrate Cart API data. * * Makes cart data available without an API request to wc/store/cart/. */ const useStoreCartApiHydration = () => { const cartData = useRef( getSetting( 'cartData' ) ); useSelect( ( select, registry ) => { if ( ! cartData.current ) { return; } const { isResolving, hasFinishedResolution } = select( CART_STORE_KEY ); const { receiveCart, receiveError, startResolution, finishResolution, } = registry.dispatch( CART_STORE_KEY ); if ( ! isResolving( 'getCartData', [] ) && ! hasFinishedResolution( 'getCartData', [] ) ) { startResolution( 'getCartData', [] ); if ( cartData.current?.code?.includes( 'error' ) ) { receiveError( cartData.current ); } else { receiveCart( cartData.current ); } finishResolution( 'getCartData', [] ); } }, [] ); }; /** * HOC that calls the useStoreCartApiHydration hook. * * @param {Function} OriginalComponent Component being wrapped. */ const withStoreCartApiHydration = ( OriginalComponent ) => { return ( props ) => { useStoreCartApiHydration(); return <OriginalComponent { ...props } />; }; }; export default withStoreCartApiHydration;