G
G
gemajane2016-07-01 07:31:51
JavaScript
gemajane, 2016-07-01 07:31:51

Field dependency in state tree in redux, how to remove?

I'm taking my first steps in ReactJS, Redux and I can't understand why changing one object in the state tree changes another object, although this is not written in action creators. I have a table with data that receives data using the fetch method, then I select a row and call the edit form. Question why change of the data in the form, changes a line in the table???
84ff4a6d3ac24b838c8dd3b83d6e7c6c.pnga16acfc1907e4e77a21870de74b8c74b.png2b9d2d3023144b0eb3f087ea8ba11676.png
Action creators

.........
export function setRowEditable(row) {
    return {
        type: SET_ROW_EDITABLE,
        rowEditable: row
    }
}
export function changeRowEditable(fieldName, newValue) {
    return (dispatch, getState)=> {
        let rowEditable = getState().myForm.rowEditable
        rowEditable[fieldName] = newValue
        dispatch(setRowEditable(rowEditable))
    }
}

reducer
export default function myModal(state = initialState, action) {
    switch (action.type) {
...........
         case SET_ROW_EDITABLE:
            return {...state, rowEditable: action.rowEditable}  
        default:
            return state
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2016-07-01
@gemajane

let rowEditable = getState().myForm.rowEditable
rowEditable[fieldName] = newValue

Is it okay if you violate the main principles of Redux - mutate the state?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question