vasanthk / react-bits

✨ React patterns, techniques, tips and tricks ✨
https://vasanthk.gitbooks.io/react-bits
Creative Commons Attribution 4.0 International
16.88k stars 1.09k forks source link

Update 05.mutating-state.md #105

Closed bhgsbatista closed 5 years ago

bhgsbatista commented 5 years ago

Replaced reference of this.state inside setState with function that takes prevState as parameter because this pattern avoids some nasty issues like:

this.setState({
  items: this.state.items.concat('lorem')
});

// items will not have 'lorem' here, oops
this.setState({
  items: this.state.items.concat('ipsum')
});