infra: add linting and formatting for js projects (#230)
* wip * wip * wip * format * wip(mobile): lint and format * cleanup * nits * nits * idiomatic react * nit * format all root files
This commit was merged in pull request #230.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
/**
|
||||
* Creates an object URL for a Blob/File and revokes it when the source changes
|
||||
* or the component unmounts. Returns null when given null.
|
||||
*/
|
||||
export function useObjectUrl(source: Blob | null): string | null {
|
||||
const [url, setUrl] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!source) return;
|
||||
const objectUrl = URL.createObjectURL(source);
|
||||
// Intended external-resource publish to sync, not a render cascade.
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setUrl(objectUrl);
|
||||
return () => {
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
setUrl(null); // in cleanup, not the effect body — so no suppression needed
|
||||
};
|
||||
}, [source]);
|
||||
|
||||
return source ? url : null;
|
||||
}
|
||||
Reference in New Issue
Block a user