Error while sorting array of objects Cannot assign to read only property '2' of object '[object Array]'

后端 未结 4 599
执笔经年
执笔经年 2020-12-09 07:05

I\'m having array of objects where object looks like this (values change):

   {
     stats: {
        hp: 2,
        mp: 0,
        defence: 4,
        agili         


        
4条回答
  •  被撕碎了的回忆
    2020-12-09 07:59

    The array is frozen to prevent mutation of the redux state. You use react cloneElement(): https://reactjs.org/docs/react-api.html#cloneelement

    [...enemies].sort((a, b) => {
                    return b.stats.speed - a.stats.speed
                })
    

提交回复
热议问题