FirebaseExtended / FirebaseExtended/reactfire

Usage of useUser with useFirestoreDocData not very compatible within custom hooks

Abierto
#423 4 comentarios 5 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

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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza rastreando los puntos de entrada useUser, useFirestore y useFirestoreDocData, y reproduce la ruta de null-user con el hook personalizado mostrado en el issue. Compara el comportamiento reportado de ReactFire v4 con el comportamiento de ReactFire v3 al que se hace referencia en el issue 249; el issue no especifica ningún archivo, prueba ni criterio concreto de finalización.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
firebase, react, typescript
Área
authentication, database, frontend
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.