UNPKG

react-firehooks

Version:

Lightweight dependency-free collection of React hooks for Firebase

16 lines (15 loc) 765 B
import { onValue } from "firebase/database"; import { useListen } from "../internal/useListen.js"; import { LoadingState } from "../internal/useLoadingValue.js"; import { isQueryEqual } from "./internal.js"; /** * Returns the DataSnapshot of the Realtime Database query * @param query Realtime Database query * @returns User, loading state, and error * - value: DataSnapshot; `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 function useObject(query) { return useListen(query !== null && query !== void 0 ? query : undefined, onValue, isQueryEqual, LoadingState); }