添加 属性 reducer redux
Add property reducer redux
我不想在减速器中向我的对象 formOpen
添加 属性 sections: []
,我从我的服务器收到我的对象 formOpen
和其他属性我想添加这个,我怎么能在这里做呢?
谢谢
import { combineReducers } from 'redux'
import * as types from '../constants/ActionTypes'
const initialState = {
isFetching: false,
formOpen: {
}
};
export function formEditor (state = initialState, action) {
switch (action.type) {
case types.RECEIVE_OPEN_FORM:
return {
...state,
isFetching: false,
formOpen: action.formOpen
};
default:
return state;
}
}
export default combineReducers({
formEditor
})
这应该可以解决问题:
export function formEditor (state = initialState, action) {
switch (action.type) {
case types.RECEIVE_OPEN_FORM:
return {
...state,
isFetching: false,
formOpen: action.formOpen
};
case types.SET_FORM_OPEN_SECTIONS:
return {
...state,
isFetching: false,
formOpen: {
...state.formOpen,
sections: action.formOpenSections
}
};
default:
return state;
}
}
我不想在减速器中向我的对象 formOpen
添加 属性 sections: []
,我从我的服务器收到我的对象 formOpen
和其他属性我想添加这个,我怎么能在这里做呢?
谢谢
import { combineReducers } from 'redux'
import * as types from '../constants/ActionTypes'
const initialState = {
isFetching: false,
formOpen: {
}
};
export function formEditor (state = initialState, action) {
switch (action.type) {
case types.RECEIVE_OPEN_FORM:
return {
...state,
isFetching: false,
formOpen: action.formOpen
};
default:
return state;
}
}
export default combineReducers({
formEditor
})
这应该可以解决问题:
export function formEditor (state = initialState, action) {
switch (action.type) {
case types.RECEIVE_OPEN_FORM:
return {
...state,
isFetching: false,
formOpen: action.formOpen
};
case types.SET_FORM_OPEN_SECTIONS:
return {
...state,
isFetching: false,
formOpen: {
...state.formOpen,
sections: action.formOpenSections
}
};
default:
return state;
}
}