Cart Normalized

This commit is contained in:
okbel
2021-01-18 16:24:22 -03:00
parent 64b25ef70b
commit d03df631ce
6 changed files with 60 additions and 44 deletions

View File

@@ -3,6 +3,7 @@ import type { SwrOptions } from '@commerce/utils/use-data'
import useCommerceCart, { CartInput } from '@commerce/cart/use-cart'
import type { Cart } from '../api/cart'
import { normalizeCart } from '../lib/normalize'
import update from 'immutability-helper'
const defaultOpts = {
url: '/api/bigcommerce/cart',
@@ -40,7 +41,9 @@ export function extendHook(
set: (x) => x,
})
return normalizeCart(response)
return update(response, {
data: { $set: normalizeCart(response.data) }
})
}
useCart.extend = extendHook