FirebaseExtended / FirebaseExtended/reactfire
Disabling queries via ReactFireOptions
- Lenguaje dominante
- TypeScript
- Estrellas
- 3.6k
- Forks
- 403
- Merge medio
- 14 h 53 min
- PR fusionados (30 d)
- 5
Descripción
I've read the discussion in #178 and am yet another person that has run into the wall of "can't use the hooks with a not-yet-defined id". I understand and agree with your desire to keep undefined/null ids as errors. But we still run into situations where the use of react-fire hooks constrains our design decisions and requires us to make several small components that issue the same query when one query would do and would allow us to present the UI in a single component as we wish.
I suggest adopting something similar to [how react-query handles this](https://react-query.tanstack.com/guides/disabling-queries). Passing in an `enabled` flag to the `ReactFireOptions` object which would prevent the query from executing if `enabled === false` (and instead returning `initialData`, if defined). This would allow the errors to persist when inadvertently passing in undefined/null, but also allow consumers to make their own design decisions when constructing dependent queries.
Alternatively, add an `exists` property to the `ObservableStatus` so that we can determine, without an additional query, whether the ref already exists. Currently when I have a dependent query I pass in an ID that I know not to exist, e.g. "-1", but I get back a document that has a firestore-generated ID and nothing else. Without the ability to disable the query or determine if the ref exists I rely on the object being otherwise empty to determine if I should return an `undefined` or not.
Guía de contribución
Línea de trabajo
The issue names ReactFireOptions and ObservableStatus as the relevant entry points; begin by tracing how the ReactFire hooks execute queries and expose status. Compare the proposed enabled behavior with the alternative exists status, including initialData handling. Done means dependent queries can avoid unintended execution or reliably determine reference existence without treating placeholder data as a result.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- firebase, react, typescript
- Área
- frontend
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100