0

I had started building a demo app using React. For immutability, I had started using immer but somehow the render() is not getting invoked on updating component state using produce() of immer library.

this.setState(produce( draft => {
      draft.categories[categoryIndex].tags[tagIndex].isEnable 
        = !draft.categories[categoryIndex].tags[tagIndex].isEnable;
    }));

Though, the produce is able to update the respective variable but the result is only getting reflected when invoking setState() with different event.

Any Help is Appreciated!.

Ajay
  • 4,773
  • 3
  • 23
  • 36
  • @Ajay, It started working. In the other event function, I am deeply updating the state categories, I believe this made it to work. Thanks for your help. – Ajay Jun 07 '19 at 14:40
  • 1
    I was using Class Instance to create Categories and Tags and immer doesn't work well with class instances. Using single JSON date tree to make it do wonders. Reference:- https://stackoverflow.com/questions/54999078/deepcopy-object-in-javascript-using-immer – Ajay Jun 09 '19 at 12:58
  • 1
    For class object https://github.com/immerjs/immer#supported-object-types – Ajay Jun 09 '19 at 13:06

0 Answers0