UNPKG

react-firehooks

Version:

Lightweight dependency-free collection of React hooks for Firebase

17 lines (16 loc) 857 B
import { get } from "firebase/database"; import { useCallback } from "react"; import { useGet } from "../internal/useGet.js"; import { isQueryEqual } from "./internal.js"; /** * Returns and updates the DataSnapshot of the Realtime Database query. Does not update the DataSnapshot once initially fetched * @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 useObjectOnce(query) { const getData = useCallback((stableQuery) => get(stableQuery), []); return useGet(query !== null && query !== void 0 ? query : undefined, getData, isQueryEqual); }