chinitacode / jamming

Codecademy Pro Intensive jamming project
0 stars 0 forks source link

Splice #3

Open cjessett opened 6 years ago

cjessett commented 6 years ago

(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 to setState.

chinitacode commented 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?

chinitacode commented 6 years ago

So you mean the code below better? removeTrack(track) { let playlist = this.state.playlistTracks; playlist.splice(playlist.indexOf(track), 1); this.setState({playlistTracks: playlist}); }