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
  • 238,746
  • 336
  • 750
  • 1,061

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
  • 5,057
  • 1
  • 27
  • 40