0

Preferably 1 line code in the constructor. I don't want to console.log() on every callback of setState

Is there some listener for changes?

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

1 Answers1

1

Use the componentDidUpdate lifecycle function to show the state change:

  componentDidUpdate(prevProps, prevState) {
   console.log(prevState, this.state);
  }

For detecting the actual change use deep object comparison.

Working Codesandbox example .

gazdagergo
  • 6,187
  • 1
  • 31
  • 45