Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update useOptimisticCart.example.tsx #2439

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export async function loader({context}: LoaderFunctionArgs) {
}

// The cart component renders each line item in the cart.
export function Cart({cart}: {cart: Cart}) {
export function Cart({cart: originalCart}: {cart: Cart}) {
// `useOptimisticCart` adds optimistic line items to the cart.
// These line items are displayed in the cart until the server responds.
const optimisticCart = useOptimisticCart(cart);
if (!optimisticCart?.lines?.nodes?.length) return <p>Nothing in cart</p>;
const cart = useOptimisticCart(originalCart);
if (!cart?.lines?.nodes?.length) return <p>Nothing in cart</p>;

return optimisticCart.lines.nodes.map((line) => (
return cart.lines.nodes.map((line) => (
<div key={line.id}>
<Link to={`/products${line.merchandise.product.handle}`}>
{line.merchandise.product.title}
Expand Down
Loading