【问题标题】:Add property reducer redux添加属性reducer redux
【发布时间】:2016-06-23 15:45:47
【问题描述】:

我不想在减速器中将属性sections: [] 添加到我的对象formOpen,我从服务器收到我的对象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
})

【问题讨论】:

    标签: redux reducers


    【解决方案1】:

    这应该可以解决问题:

    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;
        }
    }
    

    【讨论】:

    • 感谢您的帮助:)
    猜你喜欢
    • 2020-12-05
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-03
    • 1970-01-01
    相关资源
    最近更新 更多