DEV Community

Discussion on: Redux Basics Explained From A Beginner's Perspective

Collapse
dylanmesty profile image
Dylan Mestyanek Author

I'm glad you enjoyed the read! Thank you!

So the reason we have to return ...state, as well, is because what you're returning is taking place of your current state. In this case, names is the only thing in state, so it doesn't really matter.

However, say we had another array with ages, or an object in state, in addition to the names array, we'd have to be sure to copy everything from State with ...state, and then change what we need to change.

If there was another array called ages, and the names array, and we only returned names, then ages would be overridden and be gone forever. If that makes sense. :)