Skip to content Skip to sidebar Skip to footer

React Component Render Called Twice Without Changing State

I am rendering a simple react component, where no state and props are set I am logging text to console only once inside the render function but it's logged twice: rendering counter

Solution 1:

As it was written in docs:

Strict mode can’t automatically detect side effects for you, but it can help you spot them by making them a little more deterministic. This is done by intentionally double-invoking the following methods:

  • Class component constructor method
  • The render method
  • setState updater functions (the first argument)
  • The static getDerivedStateFromProps lifecycle
  • The shouldComponentUpdate method

Post a Comment for "React Component Render Called Twice Without Changing State"