JavaScript React Components Managing State and Data Flow Update State Based on a Player's Index

rashell smith
rashell smith
14,926 Points

My Delta Is undefined

handleScoreChange = (index, delta) => { this.setState( prevState => ({ score: prevState.players[index].score += delta })); console.log('index:'+ index, 'delta:' + delta); } handleRemovePlayer = (id) => { this.setState( prevState => { return { players: prevState.players.filter(p => p.id !== id) }; }); }

render() { return ( <div className="scoreboard"> <Header title="Scoreboard" totalPlayers={this.state.players.length} />

    {/* Players list */}
    {this.state.players.map( (player, index)=>
      <Player
        name={player.name}
        score={player.score}
        id={player.id}
        key={player.id.toString()}
        index={index}
        changeScore={this.handleScoreChange}
        removePlayer={this.handleRemovePlayer}
      />
    )}
  </div>
);

} }

This is just some of my code I keep getting the error that Delta is undefined when I add a the index to the function parameters.