There is a bug in your code that causes your problem, and it is unrelated to getDerivedStateFromProps and UNSAFE_componentWillReceiveProps.

The faulty line is this:

const e =, 1) 

It changes without calling setState. Never do that. The only way you are ever allowed to make any changes to this.state is via this.setState or by returning something to be merged into state from getDerivedStateFromProps, not any other way.

In order to more easily cope with changes deep in your state tree, immutable libraries come in handily. immer is currently among the top candidates in this category. Using immer, you can modify state any way you want, as long as you wrap it into a produce call using the pattern this.setState(produce(this.state, newState => { /* change newState here */ })):

import produce from 'immer';

// ...

this.setState(produce(this.state, newState => {
  const e =, 1);
  newState.undoDataRemove = e;

Hope, this can help.

Related Query

More Query from same tag