@bouko/react 3.0.6 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/index.d.ts +9 -0
- package/dist/hooks/index.js +24 -0
- package/package.json +1 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -6,3 +6,12 @@ export { default as useSound } from "./audio/sound";
|
|
|
6
6
|
export { withAudio, type DivRef, type AudioRef } from "./element/with-audio";
|
|
7
7
|
export * from "./router/params";
|
|
8
8
|
export * from "./auth";
|
|
9
|
+
export declare function useObjectUrl(): {
|
|
10
|
+
setFromBlob: (blob: Blob) => string;
|
|
11
|
+
revoke: () => void;
|
|
12
|
+
current: import("react").RefObject<string | null>;
|
|
13
|
+
};
|
|
14
|
+
export declare function useRequestGate(): {
|
|
15
|
+
next: () => number;
|
|
16
|
+
isLatest: (id: number) => boolean;
|
|
17
|
+
};
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useRef, useCallback, useEffect } from "react";
|
|
1
2
|
export { default as useElement } from "./element";
|
|
2
3
|
export { default as useContainer } from "./element/container";
|
|
3
4
|
export { default as useResize } from "./element/resize";
|
|
@@ -6,3 +7,26 @@ export { default as useSound } from "./audio/sound";
|
|
|
6
7
|
export { withAudio } from "./element/with-audio";
|
|
7
8
|
export * from "./router/params";
|
|
8
9
|
export * from "./auth";
|
|
10
|
+
export function useObjectUrl() {
|
|
11
|
+
const urlRef = useRef(null);
|
|
12
|
+
const revoke = useCallback(() => {
|
|
13
|
+
if (!urlRef.current)
|
|
14
|
+
return;
|
|
15
|
+
URL.revokeObjectURL(urlRef.current);
|
|
16
|
+
urlRef.current = null;
|
|
17
|
+
}, []);
|
|
18
|
+
const setFromBlob = useCallback((blob) => {
|
|
19
|
+
revoke();
|
|
20
|
+
const url = URL.createObjectURL(blob);
|
|
21
|
+
urlRef.current = url;
|
|
22
|
+
return url;
|
|
23
|
+
}, [revoke]);
|
|
24
|
+
useEffect(() => revoke, [revoke]);
|
|
25
|
+
return { setFromBlob, revoke, current: urlRef };
|
|
26
|
+
}
|
|
27
|
+
export function useRequestGate() {
|
|
28
|
+
const idRef = useRef(0);
|
|
29
|
+
const next = useCallback(() => ++idRef.current, []);
|
|
30
|
+
const isLatest = useCallback((id) => id === idRef.current, []);
|
|
31
|
+
return { next, isLatest };
|
|
32
|
+
}
|