G
G
Gagatyn2020-08-03 16:49:57
JavaScript
Gagatyn, 2020-08-03 16:49:57

How to correctly remove elements from a large redux state?

//state, приблизительно
state = {
 level0: [{
  id:0,
  m0: 0,
  level1: [{
   id:10,
   m1: 1,
   level2: [{
     id:20,
     m2: 2,
     level3: [{
        // ...
     }]
    }]
   }]
  }]
}


I'm floating and I can't write the code correctly that will remove the element from the state copy. Arrays of objects are nested in state. How, for example, to get level5 and remove m5 from it. element and return state without removed element?

Also share, please, sources where solutions in similar cases are described.

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Didenko, 2020-08-03
@Gagatyn

You need to make a deepclone, remove the desired element from it and return the deepclone

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question