下面的对象action.data
有一个嵌套对象address
{
name: 'Ben',
address: {
country: 'Australia',
state: 'NSW'
}
}
我应该如何在减速器中处理它?
const rootReducer = (state = initState, action) {
switch(action.type) {
switch RECEIVE_DATA:
return {...state, data: action.data}
}
}
我可以像上面那样做吗?我只是将整个对象分配给data
而不复制?
或者
const rootReducer = (state = initState, action) {
switch(action.type) {
switch RECEIVE_DATA:
const address = {...action.data.address}
const data = {...action.data, address}
return {...state, data}
}
}
或者我应该做一个对象的深层副本并将其分配给data
?谢谢