let someArray = this.state.someProperty;
someArray.push();
You are directly mutating React's state. This is a bad practice, as React's state should only be changed by this.setState(). Consider using a non-mutating Array method instead, like slice, concat, map, or filter which returns a brand new array instead.
You are then free to mutate that copied array and then pass the final version to this.setState().
let updatedPlaylistTracks = this.state.playlistTracks.concat(track);
this.setState({
playlistTracks: updatedPlaylistTracks
});
https://github.com/liftedpixel/jammming/blob/master/src/components/App/App.js#L20-L21
When you write something like
You are directly mutating React's state. This is a bad practice, as React's state should only be changed by
this.setState()
. Consider using a non-mutating Array method instead, likeslice
,concat
,map
, orfilter
which returns a brand new array instead.You are then free to mutate that copied array and then pass the final version to
this.setState()
.