mirror of
https://github.com/vercel/commerce.git
synced 2025-05-09 19:27:53 +00:00
Fix typing
This commit is contained in:
parent
4086fe403a
commit
921b87d639
@ -26,7 +26,11 @@ type NewState = {
|
|||||||
newQuantity: number;
|
newQuantity: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
function reducer(state: Cart, newState: NewState) {
|
function reducer(state: Cart | undefined, newState: NewState) {
|
||||||
|
if (!state) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
const updatedLines = state.lines.map((item: CartItem) => {
|
const updatedLines = state.lines.map((item: CartItem) => {
|
||||||
if (item.id === newState.itemId) {
|
if (item.id === newState.itemId) {
|
||||||
const singleItemAmount = Number(item.cost.totalAmount.amount) / item.quantity;
|
const singleItemAmount = Number(item.cost.totalAmount.amount) / item.quantity;
|
||||||
@ -66,7 +70,7 @@ function reducer(state: Cart, newState: NewState) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CartModal({ cart: initialCart }: { cart: Cart }) {
|
export default function CartModal({ cart: initialCart }: { cart: Cart | undefined }) {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [cart, updateCartItem] = useOptimistic(initialCart, reducer);
|
const [cart, updateCartItem] = useOptimistic(initialCart, reducer);
|
||||||
const quantityRef = useRef(cart?.totalQuantity);
|
const quantityRef = useRef(cart?.totalQuantity);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user