Home > @firebase/firestore > / > onSnapshot
onSnapshot() function
Attaches a listener for DocumentSnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks.
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>(reference: DocumentReference<T>, options: SnapshotListenOptions, observer: {
next?: (snapshot: DocumentSnapshot<T>) => void;
error?: (error: FirestoreError) => void;
complete?: () => void;
}): Unsubscribe;
Parameters
| Parameter | Type | Description |
|---|---|---|
| reference | DocumentReference<T> | A reference to the document to listen to. |
| options | SnapshotListenOptions | Options controlling the listen behavior. |
| observer | { next?: (snapshot: DocumentSnapshot<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.