question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useUser() status is "success" on first render despite the value being undefined

See original GitHub issue

Version 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:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:8

github_iconTop GitHub Comments

1reaction
jhuleattcommented, May 13, 2022

@MatthewFallon sorry I missed your comment and PR 😞 I’ll respond in your PR

1reaction
jhuleattcommented, May 13, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found