(blob?: Blob)
| 2 | |
| 3 | /** A URL that shows the blob, revoked once the blob changes or unmounts. */ |
| 4 | export const useObjectUrl = (blob?: Blob): string | undefined => { |
| 5 | const [url, setUrl] = useState<string>(); |
| 6 | |
| 7 | useEffect(() => { |
| 8 | if (!blob) { |
| 9 | setUrl(undefined); |
| 10 | |
| 11 | return undefined; |
| 12 | } |
| 13 | |
| 14 | const objectUrl = URL.createObjectURL(blob); |
| 15 | setUrl(objectUrl); |
| 16 | |
| 17 | return () => URL.revokeObjectURL(objectUrl); |
| 18 | }, [blob]); |
| 19 | |
| 20 | return url; |
| 21 | }; |
no outgoing calls
no test coverage detected