How To Use Object Spread With Nested Properties?
I'm trying to return the following in my reducer (react-redux) and it's giving me a syntax error: return { ...state, loginForm.email: action.payload.email } state = { loginForm: {
Solution 1:
Error you are getting because of the this key:
loginForm.email
It's not a valid object key.
Write it like this:
return {
...state,
loginForm: {
...state.loginForm,
email: action.payload.email
}
}
Solution 2:
I think you want something like this:
{ ...state, loginForm: { email: action.payload.email } }
Post a Comment for "How To Use Object Spread With Nested Properties?"