Usage of useUser with useFirestoreDocData not very compatible within custom hooks
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- firebase, react, typescript
- Ambito
- authentication, database, frontend
Direzione di ricerca
Inizia tracciando gli entry point useUser, useFirestore e useFirestoreDocData e riproduci il percorso null-user con l’hook personalizzato mostrato nell’issue. Confronta il comportamento segnalato di ReactFire v4 con il comportamento di ReactFire v3 citato nell’issue 249; l’issue non indica alcun file, test o criterio concreto di completamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- TypeScript
- Stelle
- 3.6k
- Fork
- 403
- Merge medio
- 5g 1h
- PR unite (30g)
- 10
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di FirebaseExtended/reactfire
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
FirebaseExtended/reactfire#801 ·
-
v5
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
FirebaseExtended/reactfire#793 ·
-
v5
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
FirebaseExtended/reactfire#790 · 2 commenti ·
-
v5
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
FirebaseExtended/reactfire#789 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
FirebaseExtended/reactfire#788 ·
Tutte le issue di FirebaseExtended/reactfire
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
bcgov/bc-wallet-mobile#4761 · 1 commento ·
-
external-issue to-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
area-deployment area-integrations triage:bot-seen
Difficoltà 2/5 Mezza giornata Idoneità per principianti 86/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
refactor
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100