Answer the question
In order to leave comments, you need to log in
How to create a shopping cart in React?
Since I'm starting to learn React, I would like to understand how the counter works here, and how to write it correctly, so that when you press the "button +" or "Button -" increase or decrease the price, and of course, when you click the Add to Cart > button, it switches to another page where the price state was saved, how to implement it
Answer the question
In order to leave comments, you need to log in
In general, the question you asked is quite interesting. However, the problem is that the answer to it is quite massive, unless, of course, the answer is complete.
Therefore, unfortunately, it will have to be reduced a little.
Imagine you have a small store with several products. For example, these will be simple phones. The structure of one product is quite simple: a picture, a title, a description, and a buy button.
Under the hood, things are a little different. We will have an array, inside of which there are objects with data. The object will include: product name, product description, product image and a unique identifier. An example of one object will be a little lower.
{
id: 0,
name: "Nokia 3310",
description: "Телефон, переживший падение в жерло вулкана",
url: "https://static.shiftdelete.net/wp-content/uploads/2018/05/nokia-3310-1-milyon-volt-yuke-dayandi-sdn-01.jpg",
price: 2800
}
{
id: 0,
name: "Nokia 3310",
description: "Телефон, переживший падение в жерло вулкана",
url: "https://static.shiftdelete.net/wp-content/uploads/2018/05/nokia-3310-1-milyon-volt-yuke-dayandi-sdn-01.jpg",
price: 2800,
count: 1
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question