Skip to content

Commit

Permalink
feat(useRTDB): add errorHandler option (#3232)
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Jul 30, 2023
1 parent 17a725e commit b5e52f5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/firebase/useRTDB/index.ts
Expand Up @@ -5,6 +5,7 @@ import { ref } from 'vue-demi'
import { tryOnScopeDispose } from '@vueuse/shared'

export interface UseRTDBOptions {
errorHandler?: (err: Error) => void
autoDispose?: boolean
}

Expand All @@ -18,6 +19,7 @@ export function useRTDB<T = any>(
options: UseRTDBOptions = {},
) {
const {
errorHandler = (err: Error) => console.error(err),
autoDispose = true,
} = options
const data = ref(undefined) as Ref<T | undefined>
Expand All @@ -26,7 +28,7 @@ export function useRTDB<T = any>(
data.value = snapshot.val()
}

const off = onValue(docRef, update)
const off = onValue(docRef, update, errorHandler)

if (autoDispose)
tryOnScopeDispose(() => off())
Expand Down

0 comments on commit b5e52f5

Please sign in to comment.