voluptasmollitia
Version:
Monorepo for the Firebase JavaScript SDK
34 lines (21 loc) • 1.51 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@firebase/firestore](./firestore.md) > [/](./firestore_.md) > [onSnapshot](./firestore_.onsnapshot.md)
## 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.
<b>Signature:</b>
```typescript
export declare function onSnapshot<T>(reference: DocumentReference<T>, observer: {
next?: (snapshot: DocumentSnapshot<T>) => void;
error?: (error: FirestoreError) => void;
complete?: () => void;
}): Unsubscribe;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| reference | [DocumentReference](./firestore_.documentreference.md)<!-- --><T> | A reference to the document to listen to. |
| observer | { next?: (snapshot: [DocumentSnapshot](./firestore_.documentsnapshot.md)<!-- --><T>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md)<!-- -->) => void; complete?: () => void; } | A single object containing <code>next</code> and <code>error</code> callbacks. |
<b>Returns:</b>
[Unsubscribe](./firestore_.unsubscribe.md)
An unsubscribe function that can be called to cancel the snapshot listener.