diff --git a/framework/bigcommerce/index.tsx b/framework/bigcommerce/index.tsx index 261aa4d28..2ff73366c 100644 --- a/framework/bigcommerce/index.tsx +++ b/framework/bigcommerce/index.tsx @@ -90,21 +90,6 @@ export type BigcommerceProvider = typeof bigcommerceProvider export const bigcommerceConfig: CommerceConfig = { locale: 'en-us', cartCookie: 'bc_cartId', - async fetcher({ url, method = 'GET', variables, body: bodyObj }) { - const hasBody = Boolean(variables || bodyObj) - const body = hasBody - ? JSON.stringify(variables ? { variables } : bodyObj) - : undefined - const headers = hasBody ? { 'Content-Type': 'application/json' } : undefined - const res = await fetch(url!, { method, body, headers }) - - if (res.ok) { - const { data } = await res.json() - return data - } - - throw await getError(res) - }, } export type BigcommerceConfig = Partial diff --git a/framework/commerce/index.tsx b/framework/commerce/index.tsx index e2dc60a9a..cb2fafcd7 100644 --- a/framework/commerce/index.tsx +++ b/framework/commerce/index.tsx @@ -14,6 +14,7 @@ import type { FetchCartInput } from './cart/use-cart' const Commerce = createContext | {}>({}) export type Provider = CommerceConfig & { + fetcher: Fetcher cart?: { useCart?: HookHandler } @@ -25,7 +26,7 @@ export type CommerceProps

= { config: CommerceConfig } -export type CommerceConfig = { fetcher: Fetcher } & Omit< +export type CommerceConfig = Omit< CommerceContextValue, 'providerRef' | 'fetcherRef' > @@ -47,7 +48,8 @@ export function CommerceProvider

({ } const providerRef = useRef(provider) - const fetcherRef = useRef(config.fetcher) + // TODO: Remove the fetcherRef + const fetcherRef = useRef(provider.fetcher) // Because the config is an object, if the parent re-renders this provider // will re-render every consumer unless we memoize the config const cfg = useMemo(