Added debounce to shipping rate selection on cart (https://github.com/woocommerce/woocommerce-blocks/pull/8498)

This commit is contained in:
Paulo Arromba 2023-03-01 13:41:20 +00:00 committed by GitHub
parent a7f471d9ff
commit 6483ee08d0
1 changed files with 12 additions and 8 deletions

View File

@ -13,6 +13,7 @@ import {
useStoreEvents,
} from '@woocommerce/base-context/hooks';
import { sanitizeHTML } from '@woocommerce/utils';
import { debounce } from 'lodash';
/**
* Internal dependencies
@ -90,14 +91,17 @@ export const ShippingRatesControlPackage = ( {
) }
</>
);
const onSelectRate = useCallback(
( newShippingRateId: string ) => {
selectShippingRate( newShippingRateId, packageId );
dispatchCheckoutEvent( 'set-selected-shipping-rate', {
shippingRateId: newShippingRateId,
} );
},
[ dispatchCheckoutEvent, packageId, selectShippingRate ]
const onSelectRate = debounce(
useCallback(
( newShippingRateId: string ) => {
selectShippingRate( newShippingRateId, packageId );
dispatchCheckoutEvent( 'set-selected-shipping-rate', {
shippingRateId: newShippingRateId,
} );
},
[ dispatchCheckoutEvent, packageId, selectShippingRate ]
),
1000
);
const packageRatesProps = {
className,