mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-02-12 08:43:38 +01:00
add object url hook
This commit is contained in:
parent
285d8d110e
commit
6fa0cfc53a
1 changed files with 17 additions and 0 deletions
17
src/app/hooks/useObjectURL.ts
Normal file
17
src/app/hooks/useObjectURL.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { useEffect, useMemo } from 'react';
|
||||
|
||||
export const useObjectURL = (object?: Blob): string | undefined => {
|
||||
const url = useMemo(() => {
|
||||
if (object) return URL.createObjectURL(object);
|
||||
return undefined;
|
||||
}, [object]);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (url) URL.revokeObjectURL(url);
|
||||
},
|
||||
[url]
|
||||
);
|
||||
|
||||
return url;
|
||||
};
|
Loading…
Reference in a new issue