From fc104c6caf9e04fb00558bcba8271d814808423a Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Fri, 22 Jan 2021 10:51:49 -0500 Subject: [PATCH] added useResponse to useWhishlist --- .../bigcommerce/wishlist/use-wishlist.tsx | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/framework/bigcommerce/wishlist/use-wishlist.tsx b/framework/bigcommerce/wishlist/use-wishlist.tsx index 870b90019..730bf19dc 100644 --- a/framework/bigcommerce/wishlist/use-wishlist.tsx +++ b/framework/bigcommerce/wishlist/use-wishlist.tsx @@ -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