voluptasmollitia
Version:
Monorepo for the Firebase JavaScript SDK
33 lines (19 loc) • 1.83 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@firebase/database](./database.md) > [off](./database.off.md)
## off() function
Detaches a callback previously attached with `on()`<!-- -->.
Detach a callback previously attached with `on()`<!-- -->. Note that if `on()` was called multiple times with the same eventType and callback, the callback will be called multiple times for each event, and `off()` must be called multiple times to remove the callback. Calling `off()` on a parent listener will not automatically remove listeners registered on child nodes, `off()` must also be called on any child listeners to remove the callback.
If a callback is not specified, all callbacks for the specified eventType will be removed. Similarly, if no eventType is specified, all callbacks for the `Reference` will be removed.
Individual listeners can also be removed by invoking their unsubscribe callbacks.
<b>Signature:</b>
```typescript
export declare function off(query: Query, eventType?: EventType, callback?: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown): void;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| query | [Query](./database.query.md) | The query that the listener was registered with. |
| eventType | [EventType](./database.eventtype.md) | One of the following strings: "value", "child\_added", "child\_changed", "child\_removed", or "child\_moved." If omitted, all callbacks for the <code>Reference</code> will be removed. |
| callback | (snapshot: [DataSnapshot](./database.datasnapshot.md)<!-- -->, previousChildName?: string \| null) => unknown | The callback function that was passed to <code>on()</code> or <code>undefined</code> to remove all callbacks. |
<b>Returns:</b>
void