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