I have a prototype e-commerce shopping cart with item and number of items to be purchased. There is a list of items each with a value (number of items to be purchased), an increment button and a delete button. I am trying to add a reset button which will set the values to zero.
I have written a handleReset
function achieve this feature.
state = {
counters: [
{ id: 1, value: 0 },
{ id: 2, value: 9 },
{ id: 3, value: 2 },
{ id: 4, value: 3 }
]
};
handleReset = () => {
let counters = [...this.state.counters];
counters = counters.map((counter, index) => {
counter.id, 0;
});
this.setState({ counters });
};
/* I need the state to look like this: */
state = {
counters: [
{ id: 1, value: 0 },
{ id: 2, value: 0 },
{ id: 3, value: 0 },
{ id: 4, value: 0 }
]
};
When I tried handleReset
as above I get the error:
Failed to compile
./src/components/counters.jsx
Line 29: Expected an assignment or function call and instead saw an expression no-unused-expressions
Search for the keywords to learn more about each error.