<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@firebase/firestore](./firestore.md) &gt; [/](./firestore_.md) &gt; [onSnapshot](./firestore_.onsnapshot_6.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>, onNext: (snapshot: QuerySnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  query | [Query](./firestore_.query.md)<!-- -->&lt;T&gt; | The query to listen to. |
|  onNext | (snapshot: [QuerySnapshot](./firestore_.querysnapshot.md)<!-- -->&lt;T&gt;) =&gt; void | A callback to be called every time a new <code>QuerySnapshot</code> is available. |
|  onError | (error: [FirestoreError](./firestore_.firestoreerror.md)<!-- -->) =&gt; void | A callback to be called if the listen fails or is cancelled. No further callbacks will occur. |
|  onCompletion | () =&gt; void | Can be provided, but will not be called since streams are never ending. |

<b>Returns:</b>

[Unsubscribe](./firestore_.unsubscribe.md)

An unsubscribe function that can be called to cancel the snapshot listener.

