quodolores
Version:
Monorepo for the Firebase JavaScript SDK
35 lines (22 loc) • 1.69 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_5.md)
## 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.
<b>Signature:</b>
```typescript
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](./firestore_.query.md)<!-- --><T> | The query to listen to. |
| options | [SnapshotListenOptions](./firestore_.snapshotlistenoptions.md) | Options controlling the listen behavior. |
| observer | { next?: (snapshot: [QuerySnapshot](./firestore_.querysnapshot.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.