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. :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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. :)