Home > @firebase/firestore > / > onSnapshot
onSnapshot() function
Attaches a listener for QuerySnapshot
events. You may either pass individual onNext
and onError
callbacks or pass a single observer object with next
and error
callbacks. The listener can be cancelled by calling the function that is returned when onSnapshot
is called.
NOTE: Although an onCompletion
callback can be provided, it will never be called because the snapshot stream is never-ending.
Signature:
export declare function onSnapshot<T>(query: Query<T>, options: SnapshotListenOptions, observer: {
next?: (snapshot: QuerySnapshot<T>) => void;
error?: (error: FirestoreError) => void;
complete?: () => void;
}): Unsubscribe;
Parameters
Parameter | Type | Description |
---|---|---|
query | Query<T> | The query to listen to. |
options | SnapshotListenOptions | Options controlling the listen behavior. |
observer | { next?: (snapshot: QuerySnapshot<T>) => void; error?: (error: FirestoreError) => void; complete?: () => void; } | A single object containing next and error callbacks. |
Returns:
An unsubscribe function that can be called to cancel the snapshot listener.