A
A
Anton2020-06-15 12:40:53
React
Anton, 2020-06-15 12:40:53

How to change the state of a specific item in the Store?

There is a store with the following content:

{routingTasks: {
 taskData: {
  message: "Успешно",
  infoTask: {
    0: {
        ID: "ZX001",
        TIME: "15.06.2020 12:20",
        ROUTE: null,
       }
    1: {...},
    2: {...},
   }
  }
 }
}

You need to update the state of a specific element, such as routingTasks.taskData.infoTask[1].ROUTE. How to do it?

I use a reducer like this:

const tasksData = handleActions({
  [setActionRequest.toString()]: (state, action) => ({
    ...state,
    ROUTE: action.payload,
  }),
},
null,
);

Action.payload receives data like this:

{ID: "ZX052",
 ROUTE: "VASYA",}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2020-06-15
@abberati

The documentation site has a whole article about it.
If you do not want to bathe, then you can take immer and write like this:

routingTasks.taskData.infoTask[1].ROUTE = "lol kek"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question