FirebaseExtended / FirebaseExtended/reactfire

Allow `useFirestoreDoc` `DocumentReference` arguments to be nullable

Abierto
#463 13 comentarios 18 reacciones 0 asignados Ver en GitHub
v5
Lenguaje dominante
TypeScript
Estrellas
3.6k
Forks
403
Merge medio
14 h 53 min
PR fusionados (30 d)
5

Descripción

`react-firebase-hooks` allows [the document reference to `useDocument` to be nullable](https://github.com/CSFrequency/react-firebase-hooks/tree/master/firestore#usedocument) and just returns undefined if it is. This was useful for paths relying on nullable info, like `auth.currentUser.uid`:
```js
const [snapshot, loading, error] = useDocument(auth.currentUser && firestore.doc(`users/${auth.currentUser.uid}`));
```
where if the user were not signed in there wouldn't be an error thrown since `useDocument` would just return `undefined`. It would be nice if a similar feature were added to reactfire, as
```js
const { status, data: firebaseDoc } = useFirestoreDoc(auth.currentUser && doc(firestore, 'users', auth.currentUser.uid));
```
won't work as the type of ref is `DocumentReference`, not `DocumentReference | null`,
```js
const { status, data: firebaseDoc } = useFirestoreDoc(doc(firestore, 'users', auth.currentUser?.uid));
```
will throw an error when the user is not signed in (as the path will become invalid), and
```js
if (auth.currentUser) {
const { status, data: firebaseDoc } = useFirestoreDoc(doc(firestore, 'users', auth.currentUser.uid));
}
```
violates the rules of hooks.
Currently relying on a rather abhorrent workaround to resolve this and it would be ideal if reactfire could support this behavior natively.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.