next-use-cart
Version:
Next React Cart
14 lines (11 loc) • 385 B
text/typescript
import { useContext } from 'react';
import { CartContext } from '../context/CartContext';
import { CartContextType } from '../types/cart';
const useCart = (): CartContextType => {
const context = useContext(CartContext);
if (context === undefined) {
throw new Error('useCart must be used within a CartProvider');
}
return context;
};
export default useCart;