Open cjessett opened 6 years ago
Thanks for the reviews!
But am I modifying state directly? I thought I was only using the index of the track to be removed here in
playlist.splice(this.state.playlistTracks.indexOf(track), 1);
Is that still a taboo?
So you mean the code below better?
removeTrack(track) { let playlist = this.state.playlistTracks; playlist.splice(playlist.indexOf(track), 1); this.setState({playlistTracks: playlist}); }
(Important) Don't modify state directly,
splice
changes the array in place. React specifically mentions this in their docs. Instead, create a new array containing the new state you would like and then pass it tosetState
.