UNPKG

react-firehooks

Version:

Lightweight dependency-free collection of React hooks for Firebase

22 lines (21 loc) 1.33 kB
import { DataSnapshot, Query } from "firebase/database"; import type { ValueHookResult } from "../common/index.js"; export type UseObjectValueResult<Value = unknown> = ValueHookResult<Value, Error>; export type UseObjectValueConverter<Value> = (snap: DataSnapshot) => Value; export interface UseObjectValueOptions<Value> { converter?: UseObjectValueConverter<Value> | undefined; initialValue?: Value | undefined; } /** * Returns and updates the DataSnapshot of the Realtime Database query * @template Value Type of the object value * @param query Realtime Database query * @param options Options to configure how the object is fetched * `converter`: Function to extract the desired data from the DataSnapshot. Similar to Firestore converters. Default: `snap.val()`. * `initialValue`: Value that is returned while the object is being fetched. * @returns User, loading state, and error * - value: Object value; `undefined` if query is currently being fetched, or an error occurred * - loading: `true` while fetching the query; `false` if the query was fetched successfully or an error occurred * - error: `undefined` if no error occurred */ export declare function useObjectValue<Value = unknown>(query: Query | undefined | null, options?: UseObjectValueOptions<Value> | undefined): UseObjectValueResult<Value>;