L
L
lookingfor22021-01-13 12:49:16
React
lookingfor2, 2021-01-13 12:49:16

How to change the property of an object of this level in Redux?

There is a state with such nesting level

const state = {
    a: "1",
    b: "2",
    items:{
        item1: {
           key1.1: 'value1.1'
           key1.1: 'value1.2'
},
           item2: {
           key2.1: 'value2.1'
           key2.1: 'value2.2'
},
    }
};


Let's say I need to reset the value 2.1 of the item2 object, which is in items, how to do this without losing the rest of the data?

did so, but is it correct?
case "CLEAR_PROJECT_ERRORS": {
    const newState = state;
    newState.items[action.payload.object][action.payload.name] = "";

    console.log("%c%s", "color: yellow;", "object",
        newState.items[action.payload.object][action.payload.object] = "");
    return newState

  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2021-01-13
@lookingfor2

The documentation has an article on this topic
https://redux.js.org/recipes/structuring-reducers/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question