UNPKG

react-firehooks

Version:

Lightweight dependency-free collection of React hooks for Firebase

20 lines (19 loc) 1.07 kB
import { getBlob } from "firebase/storage"; import { useCallback } from "react"; import { useGet } from "../internal/useGet.js"; import { isStorageRefEqual } from "./internal.js"; /** * Returns the data of a Google Cloud Storage object as a Blob * * This hook is not available in Node * @param reference Reference to a Google Cloud Storage object * @param maxDownloadSizeBytes If set, the maximum allowed size in bytes to retrieve * @returns Data, loading state, and error * - value: Object data as a Blob; `undefined` if data of the object is currently being downloaded, or an error occurred * - loading: `true` while downloading the data of the object; `false` if the data was downloaded successfully or an error occurred * - error: `undefined` if no error occurred */ export function useBlob(reference, maxDownloadSizeBytes) { const fetchBlob = useCallback(async (ref) => getBlob(ref, maxDownloadSizeBytes), [maxDownloadSizeBytes]); return useGet(reference !== null && reference !== void 0 ? reference : undefined, fetchBlob, isStorageRefEqual); }