Fix JS console error when COD is enabled and no shipping method is available. (https://github.com/woocommerce/woocommerce-blocks/pull/3086)
* only return selected shipping methods from useSelectShippingRate * add docs
This commit is contained in:
parent
80400e50da
commit
d7a8328528
|
@ -15,7 +15,9 @@ See also: https://github.com/woocommerce/woocommerce-gutenberg-products-block/tr
|
|||
* - selectShippingRate A function that immediately returns the selected
|
||||
* rate and dispatches an action generator.
|
||||
* - selectedShippingRates An object of selected shipping rates and package id as key, maintained
|
||||
* locally by a state and updated optimistically.
|
||||
* locally by a state and updated optimistically, this will only return packages that has selected
|
||||
* shipping rates.
|
||||
*
|
||||
*/
|
||||
export const useSelectShippingRate = ( shippingRates ) => {
|
||||
const throwError = useThrowError();
|
||||
|
@ -34,7 +36,9 @@ export const useSelectShippingRate = ( shippingRates ) => {
|
|||
)
|
||||
// A fromEntries ponyfill, creates an object from an array of arrays.
|
||||
.reduce( ( obj, [ key, val ] ) => {
|
||||
obj[ key ] = val;
|
||||
if ( val ) {
|
||||
obj[ key ] = val;
|
||||
}
|
||||
return obj;
|
||||
}, {} ),
|
||||
[ shippingRates ]
|
||||
|
|
Loading…
Reference in New Issue