mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
build changes
This commit is contained in:
@@ -2,13 +2,20 @@ import {
|
||||
CartProvider as CommerceCartProvider,
|
||||
useCart as useCommerceCart,
|
||||
} from 'lib/commerce/cart'
|
||||
import { FunctionComponent } from 'react'
|
||||
|
||||
export type Cart = any
|
||||
|
||||
export function CartProvider({ children }) {
|
||||
interface Props {
|
||||
children?: any
|
||||
}
|
||||
|
||||
function useCart() {
|
||||
return useCommerceCart<Cart>()
|
||||
}
|
||||
|
||||
const CartProvider: FunctionComponent<Props> = ({ children }) => {
|
||||
return <CommerceCartProvider>{children}</CommerceCartProvider>
|
||||
}
|
||||
|
||||
export function useCart() {
|
||||
return useCommerceCart<Cart>()
|
||||
}
|
||||
export { CartProvider, useCart }
|
||||
|
@@ -3,6 +3,7 @@ import {
|
||||
Connector,
|
||||
useCommerce as useCoreCommerce,
|
||||
} from 'lib/commerce'
|
||||
import { ReactNode } from 'react'
|
||||
|
||||
async function getText(res: Response) {
|
||||
try {
|
||||
@@ -35,8 +36,12 @@ export const bigcommerce: Connector = {
|
||||
fetcher,
|
||||
}
|
||||
|
||||
interface Props {
|
||||
children?: ReactNode | any
|
||||
}
|
||||
|
||||
// TODO: The connector should be extendable when a developer is using it
|
||||
export function CommerceProvider({ children }) {
|
||||
export function CommerceProvider({ children }: Props) {
|
||||
return (
|
||||
<CoreCommerceProvider connector={bigcommerce}>
|
||||
{children}
|
||||
|
@@ -1,6 +1,9 @@
|
||||
import { createContext, useContext } from 'react'
|
||||
import { createContext, useContext, FunctionComponent } from 'react'
|
||||
import useSWR, { responseInterface } from 'swr'
|
||||
import { useCommerce } from '.'
|
||||
interface Props {
|
||||
children?: any
|
||||
}
|
||||
|
||||
export type Cart = any
|
||||
|
||||
@@ -8,14 +11,14 @@ export type CartResponse<C extends Cart> = responseInterface<C, Error> & {
|
||||
isEmpty: boolean
|
||||
}
|
||||
|
||||
const CartContext = createContext<CartResponse<Cart>>(null)
|
||||
const CartContext = createContext<CartResponse<Cart> | any>(null)
|
||||
|
||||
function getCartCookie() {
|
||||
// TODO: Figure how the cart should be persisted
|
||||
return null
|
||||
}
|
||||
|
||||
export function CartProvider({ children }) {
|
||||
const CartProvider: FunctionComponent<Props> = ({ children }) => {
|
||||
const { hooks, fetcher } = useCommerce<Cart>()
|
||||
const { useCart } = hooks
|
||||
const cartId = getCartCookie()
|
||||
@@ -32,6 +35,8 @@ export function CartProvider({ children }) {
|
||||
)
|
||||
}
|
||||
|
||||
export function useCart<C extends Cart>() {
|
||||
function useCart<C extends Cart>() {
|
||||
return useContext(CartContext) as CartResponse<C>
|
||||
}
|
||||
|
||||
export { CartProvider, useCart }
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { createContext, ReactNode, useContext } from 'react'
|
||||
|
||||
const Commerce = createContext<Connector>(null)
|
||||
const Commerce = createContext<Connector | any>(null)
|
||||
|
||||
export type CommerceProps = {
|
||||
children?: ReactNode
|
||||
children?: ReactNode | any
|
||||
connector: Connector
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user