Last active
January 24, 2017 02:12
-
-
Save brettinternet/52919efb207ed43df4d8c5b65b3d47fe to your computer and use it in GitHub Desktop.
For returning new state in redux with nested objects from a reducer's initialState
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let state = { | |
nestedObj: { | |
x: 1, | |
y: 2, | |
}, | |
h: 10 | |
} | |
let addObj = { | |
z: 3 | |
} | |
fn = () => { | |
return Object.assign( {}, state, { nestedObj : Object.assign( {}, state.nestedObj, addObj ) } ); | |
} | |
fn(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A better way to handle this however is to separate the parts of state that you want to renew in different reducers. Then make state default to that specific portion of state with
( state = intialState.nestedObj , action )