I can't figure out what's going on. I add an object to the array, it is added, but the old data copies the values from the new object. This is the first time I've encountered this.
Here is the code
var next
if(cart === null){
next = 0
}else {
next = cart.length
}
switch(type){
case 'horizontal':
config['0']['type'] = type
config['0']['id'] = next
config['0'].idImg = selectSvg
if(cart === null || cart === undefined || cart.length < 1){
const news = []
news.push(config)
setCountCart(news.length)
localStorage.setItem('cart-tagstyle', JSON.stringify(news))
setCart(news)
}else {
const news = [...cart]
console.log(news);
news.push(config)
console.log(news);
setCountCart(news.length)
localStorage.setItem('cart-tagstyle', JSON.stringify(news))
setCart(news)
}
break;
I tried it without push, according to the following index, the same thing. I searched the Internet, it didn't help. I've been suffering for the second day



