The object below action.datahas a nested objectaddress
{
name: 'Ben',
address: {
country: 'Australia',
state: 'NSW'
}
}
How do I handle it in the gearbox?
const rootReducer = (state = initState, action) {
switch(action.type) {
switch RECEIVE_DATA:
return {...state, data: action.data}
}
}
Can I do this as above? that I just assigned the whole object datawithout copying?
or
const rootReducer = (state = initState, action) {
switch(action.type) {
switch RECEIVE_DATA:
const address = {...action.data.address}
const data = {...action.data, address}
return {...state, data}
}
}
Or do I need to make a deep copy of the object and assign it data? thank
source
share