Aug 8, 2017 · 1 min read
Hey Cory,
I use let copy = {…this.state} often, but only for flat objects.
Ones with arrays, I use
let copy = JSON.parse(JSON.stringify(this.state))
This second way seems to do a lot better at copying an objective. According to the place I found this little trick, it won’t always work in all cases, but it’s worked for all state I’ve used in React so far.