Understanding Cookies 🍪 thru a Shopping Cart
In this example, I've implemented a simple e-commerce scenario. The application contains a product list and a shopping cart.
Instead of storing cart information in a database, the cart state is persisted using browser cookies.
The cookie stores only the data necessary to reconstruct the cart (to know: product id and quantity):
(cookie structure) 👉
{
'pl-1': 4,
'pl-2': 1,
'pl-3': 2,
...
}
I've added quantities modifiers in order to add/delete/remove them.
What I've learned?
- Next.js Cookies 🍪
- cookie-next
- Improving TailwindCSS
- Array.reduce() (used for sum total in cart)