UNPKG

@nacelle/react-hooks

Version:

Custom convenience hooks for use when building apps with Nacelle

46 lines (45 loc) 1.98 kB
import { FC } from 'react'; import { AddToCartFunction, CartActions, CartState, ClearCartFunction, DecrementItemFunction, IncrementItemFunction, InitCartFunction, IsInCartFunction, RemoveFromCartFunction, StorageTypes, ToggleCartFunction, UpdateItemFunction } from './use-cart.types'; export declare type CartContextValue = null | CartState; export declare type CartActionContextValue = null | CartActions; export declare type CartProviderProps = { children: JSX.Element | JSX.Element[]; storage?: StorageTypes; cacheKey?: string; initCart?: InitCartFunction; addToCart?: AddToCartFunction; clearCart?: ClearCartFunction; decrementItem?: DecrementItemFunction; incrementItem?: IncrementItemFunction; removeFromCart?: RemoveFromCartFunction; toggleCart?: ToggleCartFunction; updateItem?: UpdateItemFunction; isInCart?: IsInCartFunction; }; export declare const CartProvider: FC<CartProviderProps>; /** * Provides access to the cart provider's state * * @returns an object with the cart's current state */ export declare function useCartState(): CartState | null; /** * Provides access to actions that interact with the cart * * @returns an object with functions for interacting with the cart. * * addToCart() - add an item to the cart; if the item is already in the cart, * this function will increase the quantity of that item * removeFromCart() - remove an item from the cart * incrementItem() - increment the quantity of an item in the cart * decrementItem() - decrement the quantity of an item in the cart * toggleCart() - toggles the cart's show status * clearCart() - removes all items from the cart */ export declare function useCartActions(): CartActions | null; /** * Provides access to the active isInCart function * * @returns a function which determines whether a line item is already in the cart */ export declare function useIsInCart(): IsInCartFunction;