-1

I have an array of arrays which is kept on changing on different operations, and I need to update the same in the draft of immer as shown below (Using React with Redux and Immer).

    return produce(state, draft => {
        switch (action) {
           case SCENERIO1:
                 .
                 .
   Some Logic To generate updated Array
                 .
                 .
             draft.someArrayofArrays = modifiedArrayOfArrays; 
             break;
           }
        }
    }

My Scenario is, I have 100 items in someArrayofArrays of draft. I have new updated array modifiedArrayOfArrays which I want to reassign to draft.someArrayofArrays. So, this reassigning of updated array slows down/crashes if the array size is around 100 or more.

Am I doing anything wrong, or how to update the draft if my whole array is changing on each operation?

  • Can you share all the relevant code you are working with as part of the [mcve]? You mention removing items from an array. What is the issue? How are you removing elements from the array? – Drew Reese Oct 20 '22 at 07:02
  • My question is specific to immer; when I am assigning new data to draft, it starts crashing if my array of arrays is just of length 100. So, what's the correct way to update data to the immer draft? – Mayank Singh Oct 20 '22 at 07:14
  • I don't think immer.js cares much one way or the other *what* you are saving. I suspect your issue is somewhere in the `... Some Logic To generate updated Array ...` bit with *how* you are computing the value. Either way though, we can't help diagnose or debug code we can't see. Please edit your post to include a complete [mcve]. – Drew Reese Oct 20 '22 at 15:19
  • This is an issue with immer in handling data with deep objects, some part of the issue is resolved by upgrading version 3. x of immer to 9. x – Mayank Singh Oct 28 '22 at 08:57

1 Answers1

0

= =,hello,bro Maybe it just like below

    switch(action){
       case 1:func1();//break;
       case 2:func2();//break;
    
    }

so, it is solw down after you exceeds.50 ,,hhhhh it is my guess..

  • My Question is around this area of code draft.someArrayofArrays = modifiedArrayOfArrays; – Mayank Singh Oct 20 '22 at 06:58
  • oh , you fix you question ?? maybe be , you should use binary tree data struct,this is O(logN),,,array delete is O(n) – BingShan Wang Oct 20 '22 at 07:01
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 22 '22 at 22:25