1

my component

<iframe src="https://codesandbox.io/embed/vigorous-sun-b7pf2?fontsize=14&hidenavigation=1&theme=dark" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" title="vigorous-sun-b7pf2" allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
  sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>

getDerivedStateFromProps should called when props and state in 16.4 and higher version. But why its called twice.

Please help me to understand this.

Man
  • 742
  • 1
  • 6
  • 23
  • Does this answer your question? [Why getDerivedStateFromProps is called again even though Parent Props aren't updated?](https://stackoverflow.com/questions/54266345/why-getderivedstatefromprops-is-called-again-even-though-parent-props-arent-upd) – T J Sep 15 '22 at 13:46

1 Answers1

0

It is React strict mode that helps you spot side effects.

From React 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 functions: [...]

Alessandro Sassi
  • 103
  • 1
  • 1
  • 10