#React 18 - _app.tsx console.log called twice
11 messages · Page 1 of 1 (latest)
Don't set it to false strict mode is here to catch bugs by double invoking your components
It is intended behavior
What you should do if you only want it once is wrap it in a useEffect with empty dependencies
This feature is there only in development, in production it is disabled anyways
Im agree with that
And i got my own opinion. Your app is called twice because you have useeffect with empty params. So basically when you load app.tsx, it will render the whole file till return ignoring your useEffect. After your page is loaded, app.tsx will run useEffect and that makes your app.tsx to rendered again.
Ignoring in here it could be really ignoring useEffect or useEffect is runing on async.
Strict mode actually just ignores useEffect because it invoked useEffect a second time there would be unexpected side effects, what it is trying to prevent