score:1

Accepted answer

it is because of react.strictmode

if you go to your index.js , you will find that your app component is wrapped with <react.strictmode>. if you strip off the strictmode you will notice that your app component will render only once.

refer the below doc to understand strictmode

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:

class component constructor, render, and shouldcomponentupdate methods class component static getderivedstatefromprops method function component bodies state updater functions (the first argument to setstate) functions passed to usestate, usememo, or usereducer

please refer: https://reactjs.org/docs/strict-mode.html

score:-1

return (<react.strictmode><app /><react.strictmode>)

this would solve your problem.


Related Query

More Query from same tag