React Router doesnt display UI until after being updated, all help appreciated!

Hi, so when I navigate to a differentpage in my chrome extension, the page is supposed to display a colection saved in Firebase if the user is signed in. This works, except it seems that the onAuthStateChanged doesnt run until the page is updated (i write a comment or a paragraph in dev mode) and then its able to see its authenticated and then dispalys the UI, heres an image of what i mean
14 Replies
Andy
AndyOP•2y ago
i tried global state management, and i dont htink it worked, heres my code if u want to help
Andy
AndyOP•2y ago
maybe using react-router with some sort of useeffect that wil run the onAuthStateChanged when the page is navigated to?
lab
lab•2y ago
I'm not sure how the onAuthStateChanged would work in the extension context, but I think you might want to use the chrome OAuth API it might be more responsive. Also, make sure to put these calls inside an useEffect or something like that or they will be re-run everytime your component renders
Andy
AndyOP•2y ago
great thanks! ill let u know if it works and i can send the popup tsx if needed
YAGPDB.xyz
YAGPDB.xyz•2y ago
Gave +1 Rep to @louis
Andy
AndyOP•2y ago
hey so i came up with kind of a hacky solutoin, not sure if itll work in production but maybe you'll know? basically i used useEffect and setTimeout to run after a second, which seems to then refresh the page so that auth state is checked
lab
lab•2y ago
I'd put the onAuthStateChanged inside hte useEffect as well
Andy
AndyOP•2y ago
yea unfortunately it doesnt work then
lab
lab•2y ago
if that doesn't work, it means your state rehydration wasn't successful at first render of your app
Andy
AndyOP•2y ago
damm, should i be worried? on the bright side it doesnt have the | Extension re-packaged in 1343ms! 🚀 thingy after the settimeout if that means naything
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
lab•2y ago
We don't support async function component atm
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Arcane
Arcane•2y ago
@Jheovanny has reached level 2. GG!
Want results from more Discord servers?
Add your server