Fix bug where listen query was not updating data.

This commit is contained in:
James Grugett 2022-03-01 18:45:07 -08:00
parent 45fe430a5a
commit bfee2ea954

View File

@ -1,6 +1,5 @@
import { db } from './init' import { db } from './init'
import { import {
doc,
getDoc, getDoc,
getDocs, getDocs,
onSnapshot, onSnapshot,
@ -22,7 +21,7 @@ export function listenForValue<T>(
docRef: DocumentReference, docRef: DocumentReference,
setValue: (value: T | null) => void setValue: (value: T | null) => void
) { ) {
return onSnapshot(docRef, (snapshot) => { return onSnapshot(docRef, { includeMetadataChanges: true }, (snapshot) => {
if (snapshot.metadata.fromCache) return if (snapshot.metadata.fromCache) return
const value = snapshot.exists() ? (snapshot.data() as T) : null const value = snapshot.exists() ? (snapshot.data() as T) : null
@ -34,7 +33,7 @@ export function listenForValues<T>(
query: Query, query: Query,
setValues: (values: T[]) => void setValues: (values: T[]) => void
) { ) {
return onSnapshot(query, (snapshot) => { return onSnapshot(query, { includeMetadataChanges: true }, (snapshot) => {
if (snapshot.metadata.fromCache) return if (snapshot.metadata.fromCache) return
const values = snapshot.docs.map((doc) => doc.data() as T) const values = snapshot.docs.map((doc) => doc.data() as T)