nested spread operator object 1

nested spread operator object

return { 
    ...state, 
    loginForm: {
        ...state.loginForm,
        email: action.payload.email
    } 
}

Here is what the above code is Doing:
1. We’re taking the current state and spreading it into a new object.
2. We’re taking the current loginForm and spreading it into a new object.
3. We’re taking the current email and spreading it into a new object.
4. We’re setting the email property of the loginForm to the payload of the action.

This is a lot of work to do something that seems simple.

Similar Posts