Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add property reducer redux

Tags:

redux

reducers

I wan't to add a property sections: [] to my object formOpen in the reducer, I receive my object formOpen from my server with other properties and I want to add this one, how can I do that here ? Thanks

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
})
like image 707
fandro Avatar asked Mar 09 '16 10:03

fandro


1 Answers

This should do the trick:

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;
    }
}
like image 113
Nathan Hagen Avatar answered Sep 22 '22 21:09

Nathan Hagen