react/react 에러
Uncaught TypeError: Cannot assign to read only propery '0' of obejct '[object Array]'
akjfal
2019. 11. 23. 12:58
배열을 직접 수정하려고 하면 이러한 오류가 발생한다.
Error while sorting array of objects Cannot assign to read only property '2' of object '[object Array]'
I'm having array of objects where object looks like this (values change): { stats: { hp: 2, mp: 0, defence: 4, agility: 11, speed: 6, streng...
stackoverflow.com
해결법)
1. 배열을 잘랐다가 다시 합치기
2.
const tempOption = tempProduct.data.option.map((item, index) => {
if(index !== arraynum){
return item
}
return{
...item,
[e.target.name]: e.target.value
}
})
map함수를 통해서 재 생성