I am trying to remove an item from my state using React Hooks. I can't figure out what I am doing wrong.
My data looks as follows and I'm trying to remove individual item within the 'items' array.
const MYDATA = {
id: '0001',
title: 'A good title',
items: [
{
itemid: 0,
title: 'Cheddar',
variants: [
{ id: '062518', grams: 200, price: 3.00},
{ id: '071928', grams: 400, price: 5.50},
]
},
{
itemid: 1,
title: 'Edam',
variants: [
{ id: '183038', grams: 220, price: 2.50},
{ id: '194846', grams: 460, price: 4.99},
]
},
{
itemid: 2,
title: 'Red Leicester',
variants: [
{ id: '293834', grams: 420, price: 4.25},
{ id: '293837', grams: 660, price: 5.99},
]
}
]
}
When i click on my 'Remove' button map breaks, and I think this is because my my state is malformed, but I'm not sure.
An example of the problem I face can be seen here - https://codesandbox.io/s/frosty-joliot-4wp1q?file=/src/App.js
Any help would be greatly appreciated.