<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@firebase/database](./database.md) &gt; [onValue](./database.onvalue_1.md)

## onValue() function

Listens for data changes at a particular location.

This is the primary way to read data from a Database. Your callback will be triggered for the initial data and again whenever the data changes. Invoke the returned unsubscribe callback to stop receiving updates. See [Retrieve Data on the Web](https://firebase.google.com/docs/database/web/retrieve-data) for more details.

An `onValue` event will trigger once with the initial data stored at this location, and then trigger again each time the data changes. The `DataSnapshot` passed to the callback will be for the location at which `on()` was called. It won't trigger until the entire contents has been synchronized. If the location has no data, it will be triggered with an empty `DataSnapshot` (`val()` will return `null`<!-- -->).

<b>Signature:</b>

```typescript
export declare function onValue(query: Query, callback: (snapshot: DataSnapshot) => unknown, options: ListenOptions): Unsubscribe;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  query | [Query](./database.query.md) | The query to run. |
|  callback | (snapshot: [DataSnapshot](./database.datasnapshot.md)<!-- -->) =&gt; unknown | A callback that fires when the specified event occurs. The callback will be passed a DataSnapshot. |
|  options | [ListenOptions](./database.listenoptions.md) | An object that can be used to configure <code>onlyOnce</code>, which then removes the listener after its first invocation. |

<b>Returns:</b>

[Unsubscribe](./database.unsubscribe.md)

A function that can be invoked to remove the listener.

