Read data from a cart
This guide shows you how to read a user's cart.
Requirements
Anchor link to section titled "Requirements"- You've completed the quickstart guide.
- You've set up a cart handler.
Step 1: Get a visitor's cart
Anchor link to section titled "Step 1: Get a visitor's cart"Use the cart
, created from createCartHandler
, to get a user's cart. You don't need to provide a cart ID because it's already handled by the cart handler. cart.get()
returns a promise. Use Remix's defer so that the cart data is deferred, and streamed to the browser.
Step 2: Server render the content of the cart
Anchor link to section titled "Step 2: Server render the content of the cart"You can get the content of the cart using Remix's useMatches
hook, because you made it available in the root loader. Since the data is deferred, you'll need to wait for the data.
- Learn how to manage items in a cart.
- Learn how to render the cart client side.