Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

549 B
Raw Blame
import { useCallback, useEffect, useRef } from "react";

export function useBlobUrls() {
  const urlsRef = useRef<Set<string>>(new Set());

  useEffect(
    () => () => {
      for (const url of urlsRef.current) {
        URL.revokeObjectURL(url);
      }
    },
    [],
  );

  // Stable identity so callers can hold it in useCallback dependencies.
  const createBlobUrl = useCallback((blob: Blob | File): string => {
    const url = URL.createObjectURL(blob);
    urlsRef.current.add(url);
    return url;
  }, []);

  return { createBlobUrl };
}