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