#React 18 - _app.tsx console.log called twice

11 messages · Page 1 of 1 (latest)

surreal furnace
#

Hi all! We noticed that the _app.tsx is being run twice? This causes a bug downstream where our loadAuth logic also is called twice

#

Seems to have been fixed by setting this to false

sinful coyote
#

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

ionic dirge
#

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.

sinful coyote