countersの入れ替えについて教えて下さい

stateの値を直接更新することは禁止されているため、必要な処理になります。
2020年12月15日
ユーザー

本解説ではAppのClass内のcountersをmap関数を使ってローカルのcountersに入れ直してますが、入換えなくても以下のコーディングで正常にカウントアップ出来るように思うのですが、なぜ入れ替えが必要なのでしょうか?

countUp(counter){
this.setState(prevState => {
const pos = this.state.counters.map(counterTmp=> {
return(counterTmp.id)
}).indexOf(counter.id)

this.state.counters[pos].count++;
this.state.total=prevState.total+1;
return({counters:this.state.counters,total:this.state.total})
})
}

よろしくお願いいたします。

この回答を見るにはプレミアムプランへの登録が必要です

プレミアムプランとは?