Когда вы делаете this.setState({dancer, totalScore: 10});
, вы создаете dancer
в состоянии, в результате которого, как показано ниже
this.state = {
dancers: [{name: "Dancer1", score1: 10, score2: 8, score3: 7, totalScore: 0},
{name: "Dancer2", score1: 5, score2: 7, score3: 8, totalScore: 0},
{name: "Dancer3", score1: 6, score2: 6, score3: 7, totalScore: 0},
{name: "Dancer4", score1: 9, score2: 5, score3: 6, totalScore: 0},
{name: "Dancer5", score1: 8, score2: 8, score3: 7, totalScore: 0},
{name: "Dancer6", score1: 10, score2: 9, score3: 10, totalScore: 0},
{name: "Dancer7", score1: 6, score2: 10, score3: 9, totalScore: 0},
{name: "Dancer8", score1: 8, score2: 4, score3: 6, totalScore: 0},]
dancer: {name: "Dancer8", score1: 8, score2: 4, score3: 6, totalScore: 0},
totalScore: 10,
}
Так что вы должны сделать, как показано ниже,
const calculatedDancers = dancers.map(dancer => {
return { ...dancer, totalScore: 10 }
})
this.setState({ dancers: calculatedDancers })