Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const players = this.state.players.map(player => {
- return { ...player, updated: player.id === id };
- });
- this.setState({players: players});
- updatePlayer = id => {
- const players = this.state.players.map(player => {
- player.updated = player.id === id ? true:false;
- return player
- });
- this.setState({players: players});
- }
- updatePlayer = id => {
- const playerObj = this.state.players.find(item => {
- return item.id === id
- })
- if (playerObj) {
- playerObj.updated = true
- this.setState({ playerObj })
- }
- }
- this.state = {
- players: [p1, p2 ,p3, p4], // each p is a player.
- //notice that playerObj is now a reference to some of the P on the players array
- playerObj: {
- ...playerstuff,
- updated: true
- }
- }
Add Comment
Please, Sign In to add comment