Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Usage of useUser with useFirestoreDocData not very compatible within custom hooks

Offen
#423 4 Kommentare 5 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
25/100
Issue-Typ
Feature
Klarheit
Muss geklärt werden
Aktivitätsstatus
Veraltet
Tech-Stack
firebase, react, typescript

Rechercherichtung

Beginne damit, die Einstiegspunkte useUser, useFirestore und useFirestoreDocData nachzuverfolgen, und reproduziere den Pfad für einen null-user mit dem im Issue gezeigten benutzerdefinierten Hook. Vergleiche das gemeldete Verhalten von ReactFire v4 mit dem in Issue 249 referenzierten Verhalten von ReactFire v3; das Issue nennt keine Datei, keinen Test und kein konkretes Abschlusskriterium.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

v5
Version info

React: 18 experimental

Firebase: 9

ReactFire: 4

Other (e.g. Node, browser, operating system) (if applicable):

Test case
Steps to reproduce
const useMyHook= () => {
    
    const firestore = useFirestore();
    const {data: user} = useUser();   
    const ref = user && doc(firestore, "users", user.uid);
    const {data: userData} = useFirestoreDocData(ref);

    return userData;
}
Behavior

Since useUser is returning the type User | null , we need to check, if the user is available. But in the case when the user is null, useFirestoreDocData cannot be called, since the ref would not exist. In react we are not allowed to write:
const {data: userData} = ref && useFirestoreDocData(ref)

One way to get around this issue is by passing in the user as a prop, but it does not seem to be convenient, if one wants to use this hook within another hook. We would just push the issue upwards until we reach a component that is again wrapped by a component that knows if the user exists:

  • component that checks if user exists (like deprecated AuthCheck)
  • component that is rendered when user exists
  • hook that is called within that component

Another alternative for typescript is writing user! with exclamation mark, but this does not feel proper.

I hope the case is clear and you might know a better way to deal with it.
I think with react-fire v3 (fb v8) I wasn't experiencing this issue. Since it was probably solved with this issue: https://github.com/FirebaseExtended/reactfire/issues/249

Vorherrschende Sprache
TypeScript
Sterne
3.6k
Forks
403
Ø Merge
5 T. 1 Std.
Gemergte PRs (30 T.)
10

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus FirebaseExtended/reactfire

Alle Issues in FirebaseExtended/reactfire

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.