forked from crowetic/commerce
added useResponse to useWhishlist
This commit is contained in:
parent
bafb8a4479
commit
fc104c6caf
@ -1,6 +1,6 @@
|
||||
import { HookFetcher } from '@commerce/utils/types'
|
||||
import { SwrOptions } from '@commerce/utils/use-data'
|
||||
import defineProperty from '@commerce/utils/define-property'
|
||||
import useResponse from '@commerce/utils/use-response'
|
||||
import useCommerceWishlist from '@commerce/wishlist/use-wishlist'
|
||||
import type { Wishlist } from '../api/wishlist'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
@ -56,19 +56,18 @@ export function extendHook(
|
||||
...swrOptions,
|
||||
}
|
||||
)
|
||||
|
||||
// Uses a getter to only calculate the prop when required
|
||||
// response.data is also a getter and it's better to not trigger it early
|
||||
if (!('isEmpty' in response)) {
|
||||
defineProperty(response, 'isEmpty', {
|
||||
get() {
|
||||
return (response.data?.items?.length || 0) <= 0
|
||||
const res = useResponse(response, {
|
||||
descriptors: {
|
||||
isEmpty: {
|
||||
get() {
|
||||
return (response.data?.items?.length || 0) <= 0
|
||||
},
|
||||
set: (x) => x,
|
||||
},
|
||||
set: (x) => x,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
return response
|
||||
return res
|
||||
}
|
||||
|
||||
useWishlist.extend = extendHook
|
||||
|
Loading…
x
Reference in New Issue
Block a user