stefem / jammming

CodeAcademy project
0 stars 0 forks source link

Adding tracks to playlist #4

Open ghost opened 6 years ago

ghost commented 6 years ago

https://github.com/stefem/jammming/blob/master/src/components/App/App.js#L28

Nice job using .find() to determine if a track ID exists in the current playlist before adding it in.

Iterator methods can make it easier for you to write terse and expressive code. This is much better than relying on the traditional loop.

https://github.com/stefem/jammming/blob/master/src/components/App/App.js#L29

Consider rewriting this code so you don't have a whole block for just an empty return statement.

         if (!this.state.playListTracks.find(savedTrack => savedTrack.id === track.id)) {
             let tracks = this.state.playListTracks.concat(track); //rather than use push, use concat to merge track with playlistTracks and create a new array.
             this.setState({playListTracks: tracks});
         }