From 7758ea319966c58192ede133a7b9280350ae52c6 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Fri, 9 Oct 2020 11:26:39 -0500 Subject: [PATCH] Removed the CartProvider --- lib/bigcommerce/cart/index.tsx | 4 +--- lib/commerce/cart/index.tsx | 18 ++---------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/bigcommerce/cart/index.tsx b/lib/bigcommerce/cart/index.tsx index 15f257782..a2cfae716 100644 --- a/lib/bigcommerce/cart/index.tsx +++ b/lib/bigcommerce/cart/index.tsx @@ -1,10 +1,8 @@ -import { CartProvider, useCart as useCommerceCart } from '@lib/commerce/cart' +import { useCart as useCommerceCart } from '@lib/commerce/cart' import type { Cart } from '../api/cart' export type { Cart } -export { CartProvider } - export function useCart() { const cart = useCommerceCart() diff --git a/lib/commerce/cart/index.tsx b/lib/commerce/cart/index.tsx index b9e790dc5..70ed9d12d 100644 --- a/lib/commerce/cart/index.tsx +++ b/lib/commerce/cart/index.tsx @@ -1,4 +1,3 @@ -import { FC, createContext, useContext, useMemo } from 'react' import useSWR, { responseInterface } from 'swr' import Cookies from 'js-cookie' import { useCommerce } from '..' @@ -9,28 +8,15 @@ export type CartResponse = responseInterface & { isEmpty: boolean } -export type CartProviderProps = { - query?: string - url?: string -} - -const CartContext = createContext({}) - -const CartProvider: FC = ({ children, query, url }) => { - const value = useMemo(() => ({ query, url }), [query, url]) - return {children} -} - function useCart() { const { fetcherRef, cartCookie } = useCommerce() const fetcher = (url?: string, query?: string) => Cookies.get(cartCookie) ? fetcherRef.current({ url, query }) : null - const { url = CART_API, query } = useContext(CartContext) - const response = useSWR([url, query], fetcher, { + const response = useSWR([CART_API, undefined], fetcher, { revalidateOnFocus: false, }) return Object.assign(response, { isEmpty: true }) as CartResponse } -export { CartProvider, useCart } +export { useCart }