useUser() status is "success" on first render despite the value being undefined
See original GitHub issueVersion info
Next: 12.0.7 React: 17.0.2 Firebase: ^9.6.1 ReactFire: ^4.2.1 Suspense mode: off
Test case
// FirebaseProviders.tsx
const firebaseConfig = {
// ...
}
function FirebaseServices({ children }) {
const app = useFirebaseApp();
const firestore = getFirestore(app);
const auth = getAuth(app);
const storage = getStorage(app);
return (
<FirestoreProvider sdk={firestore}>
<StorageProvider sdk={storage}>
<AuthProvider sdk={auth}>{children}</AuthProvider>
</StorageProvider>
</FirestoreProvider>
);
}
export default function FirebaseProviders({ children }) {
return (
<FirebaseAppProvider firebaseConfig={firebaseConfig}>
<FirebaseServices>{children}</FirebaseServices>
</FirebaseAppProvider>
);
}
// MainMenu.tsx
export default function MainMenu() {
const { status, data: user } = useUser();
console.log("status", status, "user", user);
return <div>test</div>
}
Expected Output
status loading user undefined (first render)
status success user null (2nd render)
I expect status === “loading” for the first render
Actual behavior
status success user undefined (first render)
status success user null (2nd render)
I get status === “success” for the first render despite the value still being undefined at that point
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:8
Top Results From Across the Web
Value not defined in first render but defined in next render
I think your problem is related to the setName method. In the line after setName console.log(namesArr) will be undefined.
Read more >The React Mega-Tutorial, Chapter 8: Authentication
The state variable remains set to the initial undefined value until the user information is returned, so any components that need to render...
Read more >Safari Technology Preview Release Notes - Apple Developer
Fixed non-breaking space getting inserted instead of a normal space character between text nodes in contenteditable (257136@main) ...
Read more >The Clerk object is the core of the ClerkJS SDK.
When a session is loading, user and session will be undefined. Parameters. Name, Type, Description. listener, (resources: Resources) => void.
Read more >Google Visualization API Reference | Charts
A null or undefined value for minValue (or maxValue ) means that the lower ... chartWrapper - A ChartWrapper object defining the initial...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@MatthewFallon sorry I missed your comment and PR 😞 I’ll respond in your PR
The fix for this is available in a canary build:
npm install reactfire@4.0.0-exp.eb1428b
Since today is Friday, I’m going to wait to publish it as
4.2.2
until Monday