chadtmiller.com/pds.js
An atproto PDS in JavaScript, for Cloudflare Workers and Node
0
0
import { useEffect, useState } from 'react';
/**
* The bytes as an object URL that lives as long as the component.
* @param {Uint8Array|null|undefined} bytes
* @param {string} mediaType
* @returns {string} '' until the URL exists
*/
export function useObjectUrl(bytes, mediaType) {
const [url, setUrl] = useState('');
useEffect(() => {
if (!bytes) return undefined;
const next = URL.createObjectURL(
new Blob([/** @type {BlobPart} */ (bytes)], { type: mediaType }),
);
setUrl(next);
return () => URL.revokeObjectURL(next);
}, [bytes, mediaType]);
return url;
}