@opensite/hooks 0.1.0
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/LICENSE +28 -0
- package/README.md +102 -0
- package/dist/browser/opensite-hooks.umd.cjs +2 -0
- package/dist/browser/opensite-hooks.umd.js +2 -0
- package/dist/browser/opensite-hooks.umd.js.map +1 -0
- package/dist/core/index.cjs +16 -0
- package/dist/core/index.d.ts +24 -0
- package/dist/core/index.js +16 -0
- package/dist/core/useBoolean.cjs +8 -0
- package/dist/core/useBoolean.d.ts +8 -0
- package/dist/core/useBoolean.js +8 -0
- package/dist/core/useCopyToClipboard.cjs +67 -0
- package/dist/core/useCopyToClipboard.d.ts +9 -0
- package/dist/core/useCopyToClipboard.js +67 -0
- package/dist/core/useDebounceCallback.cjs +83 -0
- package/dist/core/useDebounceCallback.d.ts +11 -0
- package/dist/core/useDebounceCallback.js +83 -0
- package/dist/core/useDebounceValue.cjs +13 -0
- package/dist/core/useDebounceValue.d.ts +2 -0
- package/dist/core/useDebounceValue.js +13 -0
- package/dist/core/useEventListener.cjs +40 -0
- package/dist/core/useEventListener.d.ts +6 -0
- package/dist/core/useEventListener.js +40 -0
- package/dist/core/useHover.cjs +14 -0
- package/dist/core/useHover.d.ts +1 -0
- package/dist/core/useHover.js +14 -0
- package/dist/core/useIsClient.cjs +8 -0
- package/dist/core/useIsClient.d.ts +1 -0
- package/dist/core/useIsClient.js +8 -0
- package/dist/core/useIsomorphicLayoutEffect.cjs +2 -0
- package/dist/core/useIsomorphicLayoutEffect.d.ts +2 -0
- package/dist/core/useIsomorphicLayoutEffect.js +2 -0
- package/dist/core/useLocalStorage.cjs +63 -0
- package/dist/core/useLocalStorage.d.ts +9 -0
- package/dist/core/useLocalStorage.js +63 -0
- package/dist/core/useMap.cjs +39 -0
- package/dist/core/useMap.d.ts +9 -0
- package/dist/core/useMap.js +39 -0
- package/dist/core/useMediaQuery.cjs +26 -0
- package/dist/core/useMediaQuery.d.ts +4 -0
- package/dist/core/useMediaQuery.js +26 -0
- package/dist/core/useOnClickOutside.cjs +30 -0
- package/dist/core/useOnClickOutside.d.ts +3 -0
- package/dist/core/useOnClickOutside.js +30 -0
- package/dist/core/usePrevious.cjs +8 -0
- package/dist/core/usePrevious.d.ts +1 -0
- package/dist/core/usePrevious.js +8 -0
- package/dist/core/useResizeObserver.cjs +37 -0
- package/dist/core/useResizeObserver.d.ts +3 -0
- package/dist/core/useResizeObserver.js +37 -0
- package/dist/core/useSessionStorage.cjs +63 -0
- package/dist/core/useSessionStorage.d.ts +9 -0
- package/dist/core/useSessionStorage.js +63 -0
- package/dist/core/useThrottle.cjs +65 -0
- package/dist/core/useThrottle.d.ts +5 -0
- package/dist/core/useThrottle.js +65 -0
- package/dist/hooks/index.cjs +16 -0
- package/dist/hooks/index.d.ts +24 -0
- package/dist/hooks/index.js +16 -0
- package/dist/hooks/useBoolean.cjs +1 -0
- package/dist/hooks/useBoolean.d.ts +2 -0
- package/dist/hooks/useBoolean.js +1 -0
- package/dist/hooks/useCopyToClipboard.cjs +1 -0
- package/dist/hooks/useCopyToClipboard.d.ts +2 -0
- package/dist/hooks/useCopyToClipboard.js +1 -0
- package/dist/hooks/useDebounceCallback.cjs +1 -0
- package/dist/hooks/useDebounceCallback.d.ts +2 -0
- package/dist/hooks/useDebounceCallback.js +1 -0
- package/dist/hooks/useDebounceValue.cjs +1 -0
- package/dist/hooks/useDebounceValue.d.ts +2 -0
- package/dist/hooks/useDebounceValue.js +1 -0
- package/dist/hooks/useEventListener.cjs +1 -0
- package/dist/hooks/useEventListener.d.ts +1 -0
- package/dist/hooks/useEventListener.js +1 -0
- package/dist/hooks/useHover.cjs +1 -0
- package/dist/hooks/useHover.d.ts +1 -0
- package/dist/hooks/useHover.js +1 -0
- package/dist/hooks/useIsClient.cjs +1 -0
- package/dist/hooks/useIsClient.d.ts +1 -0
- package/dist/hooks/useIsClient.js +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect.cjs +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect.js +1 -0
- package/dist/hooks/useLocalStorage.cjs +1 -0
- package/dist/hooks/useLocalStorage.d.ts +2 -0
- package/dist/hooks/useLocalStorage.js +1 -0
- package/dist/hooks/useMap.cjs +1 -0
- package/dist/hooks/useMap.d.ts +2 -0
- package/dist/hooks/useMap.js +1 -0
- package/dist/hooks/useMediaQuery.cjs +1 -0
- package/dist/hooks/useMediaQuery.d.ts +2 -0
- package/dist/hooks/useMediaQuery.js +1 -0
- package/dist/hooks/useOnClickOutside.cjs +1 -0
- package/dist/hooks/useOnClickOutside.d.ts +1 -0
- package/dist/hooks/useOnClickOutside.js +1 -0
- package/dist/hooks/usePrevious.cjs +1 -0
- package/dist/hooks/usePrevious.d.ts +1 -0
- package/dist/hooks/usePrevious.js +1 -0
- package/dist/hooks/useResizeObserver.cjs +1 -0
- package/dist/hooks/useResizeObserver.d.ts +1 -0
- package/dist/hooks/useResizeObserver.js +1 -0
- package/dist/hooks/useSessionStorage.cjs +1 -0
- package/dist/hooks/useSessionStorage.d.ts +2 -0
- package/dist/hooks/useSessionStorage.js +1 -0
- package/dist/hooks/useThrottle.cjs +1 -0
- package/dist/hooks/useThrottle.d.ts +2 -0
- package/dist/hooks/useThrottle.js +1 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/package.json +252 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
|
|
3
|
+
const isRefObject = (value) => !!value && typeof value === "object" && "current" in value;
|
|
4
|
+
export function useResizeObserver(target, onResize, options) {
|
|
5
|
+
const callbackRef = useRef(onResize);
|
|
6
|
+
const entryRef = useRef(null);
|
|
7
|
+
const [entry, setEntry] = useState(null);
|
|
8
|
+
useIsomorphicLayoutEffect(() => {
|
|
9
|
+
callbackRef.current = onResize;
|
|
10
|
+
}, [onResize]);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (typeof ResizeObserver === "undefined") {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const element = typeof Element !== "undefined" && target instanceof Element
|
|
16
|
+
? target
|
|
17
|
+
: isRefObject(target)
|
|
18
|
+
? target.current
|
|
19
|
+
: null;
|
|
20
|
+
if (!element) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const observer = new ResizeObserver((entries) => {
|
|
24
|
+
const firstEntry = entries[0];
|
|
25
|
+
entryRef.current = firstEntry;
|
|
26
|
+
if (callbackRef.current) {
|
|
27
|
+
callbackRef.current(firstEntry);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
setEntry(firstEntry);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
observer.observe(element, options);
|
|
34
|
+
return () => observer.disconnect();
|
|
35
|
+
}, [options, target]);
|
|
36
|
+
return callbackRef.current ? entryRef.current : entry;
|
|
37
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
type TargetElement<T extends Element> = React.RefObject<T> | T | null;
|
|
2
|
+
export declare function useResizeObserver<T extends Element>(target: TargetElement<T>, onResize?: (entry: ResizeObserverEntry) => void, options?: ResizeObserverOptions): ResizeObserverEntry | null;
|
|
3
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
|
|
3
|
+
const isRefObject = (value) => !!value && typeof value === "object" && "current" in value;
|
|
4
|
+
export function useResizeObserver(target, onResize, options) {
|
|
5
|
+
const callbackRef = useRef(onResize);
|
|
6
|
+
const entryRef = useRef(null);
|
|
7
|
+
const [entry, setEntry] = useState(null);
|
|
8
|
+
useIsomorphicLayoutEffect(() => {
|
|
9
|
+
callbackRef.current = onResize;
|
|
10
|
+
}, [onResize]);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (typeof ResizeObserver === "undefined") {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const element = typeof Element !== "undefined" && target instanceof Element
|
|
16
|
+
? target
|
|
17
|
+
: isRefObject(target)
|
|
18
|
+
? target.current
|
|
19
|
+
: null;
|
|
20
|
+
if (!element) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const observer = new ResizeObserver((entries) => {
|
|
24
|
+
const firstEntry = entries[0];
|
|
25
|
+
entryRef.current = firstEntry;
|
|
26
|
+
if (callbackRef.current) {
|
|
27
|
+
callbackRef.current(firstEntry);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
setEntry(firstEntry);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
observer.observe(element, options);
|
|
34
|
+
return () => observer.disconnect();
|
|
35
|
+
}, [options, target]);
|
|
36
|
+
return callbackRef.current ? entryRef.current : entry;
|
|
37
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
export function useSessionStorage(key, initialValue, options = {}) {
|
|
3
|
+
const { initializeWithValue = true, serialize = JSON.stringify, deserialize = JSON.parse, listenToStorageChanges = false, } = options;
|
|
4
|
+
const initialValueRef = useRef(initialValue);
|
|
5
|
+
const readValue = useCallback(() => {
|
|
6
|
+
if (typeof window === "undefined") {
|
|
7
|
+
return initialValueRef.current;
|
|
8
|
+
}
|
|
9
|
+
if (!initializeWithValue) {
|
|
10
|
+
return initialValueRef.current;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const item = window.sessionStorage.getItem(key);
|
|
14
|
+
return item ? deserialize(item) : initialValueRef.current;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return initialValueRef.current;
|
|
18
|
+
}
|
|
19
|
+
}, [deserialize, initializeWithValue, key]);
|
|
20
|
+
const [storedValue, setStoredValue] = useState(() => readValue());
|
|
21
|
+
const setValue = useCallback((value) => {
|
|
22
|
+
setStoredValue((current) => {
|
|
23
|
+
const valueToStore = typeof value === "function"
|
|
24
|
+
? value(current)
|
|
25
|
+
: value;
|
|
26
|
+
if (typeof window !== "undefined") {
|
|
27
|
+
try {
|
|
28
|
+
window.sessionStorage.setItem(key, serialize(valueToStore));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Ignore write errors (quota/security)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return valueToStore;
|
|
35
|
+
});
|
|
36
|
+
}, [key, serialize]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
setStoredValue(readValue());
|
|
39
|
+
}, [readValue]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (typeof window === "undefined" || !listenToStorageChanges) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const handleStorageChange = (event) => {
|
|
45
|
+
if (event.key !== key) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (event.newValue === null) {
|
|
49
|
+
setStoredValue(initialValueRef.current);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
setStoredValue(deserialize(event.newValue));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
setStoredValue(initialValueRef.current);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
window.addEventListener("storage", handleStorageChange);
|
|
60
|
+
return () => window.removeEventListener("storage", handleStorageChange);
|
|
61
|
+
}, [deserialize, key, listenToStorageChanges]);
|
|
62
|
+
return [storedValue, setValue];
|
|
63
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface SessionStorageOptions<T> {
|
|
2
|
+
initializeWithValue?: boolean;
|
|
3
|
+
serialize?: (value: T) => string;
|
|
4
|
+
deserialize?: (value: string) => T;
|
|
5
|
+
listenToStorageChanges?: boolean;
|
|
6
|
+
}
|
|
7
|
+
type StoredSetter<T> = (value: T | ((current: T) => T)) => void;
|
|
8
|
+
export declare function useSessionStorage<T>(key: string, initialValue: T, options?: SessionStorageOptions<T>): [T, StoredSetter<T>];
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
export function useSessionStorage(key, initialValue, options = {}) {
|
|
3
|
+
const { initializeWithValue = true, serialize = JSON.stringify, deserialize = JSON.parse, listenToStorageChanges = false, } = options;
|
|
4
|
+
const initialValueRef = useRef(initialValue);
|
|
5
|
+
const readValue = useCallback(() => {
|
|
6
|
+
if (typeof window === "undefined") {
|
|
7
|
+
return initialValueRef.current;
|
|
8
|
+
}
|
|
9
|
+
if (!initializeWithValue) {
|
|
10
|
+
return initialValueRef.current;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const item = window.sessionStorage.getItem(key);
|
|
14
|
+
return item ? deserialize(item) : initialValueRef.current;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return initialValueRef.current;
|
|
18
|
+
}
|
|
19
|
+
}, [deserialize, initializeWithValue, key]);
|
|
20
|
+
const [storedValue, setStoredValue] = useState(() => readValue());
|
|
21
|
+
const setValue = useCallback((value) => {
|
|
22
|
+
setStoredValue((current) => {
|
|
23
|
+
const valueToStore = typeof value === "function"
|
|
24
|
+
? value(current)
|
|
25
|
+
: value;
|
|
26
|
+
if (typeof window !== "undefined") {
|
|
27
|
+
try {
|
|
28
|
+
window.sessionStorage.setItem(key, serialize(valueToStore));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Ignore write errors (quota/security)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return valueToStore;
|
|
35
|
+
});
|
|
36
|
+
}, [key, serialize]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
setStoredValue(readValue());
|
|
39
|
+
}, [readValue]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (typeof window === "undefined" || !listenToStorageChanges) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const handleStorageChange = (event) => {
|
|
45
|
+
if (event.key !== key) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (event.newValue === null) {
|
|
49
|
+
setStoredValue(initialValueRef.current);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
setStoredValue(deserialize(event.newValue));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
setStoredValue(initialValueRef.current);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
window.addEventListener("storage", handleStorageChange);
|
|
60
|
+
return () => window.removeEventListener("storage", handleStorageChange);
|
|
61
|
+
}, [deserialize, key, listenToStorageChanges]);
|
|
62
|
+
return [storedValue, setValue];
|
|
63
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
export function useThrottle(value, interval, options = {}) {
|
|
3
|
+
const leading = options.leading ?? true;
|
|
4
|
+
const trailing = options.trailing ?? true;
|
|
5
|
+
const wait = Math.max(0, interval);
|
|
6
|
+
const [throttledValue, setThrottledValue] = useState(value);
|
|
7
|
+
const lastExecutedRef = useRef(0);
|
|
8
|
+
const timeoutRef = useRef(null);
|
|
9
|
+
const pendingValueRef = useRef(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (wait === 0) {
|
|
12
|
+
setThrottledValue(value);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const now = Date.now();
|
|
16
|
+
if (lastExecutedRef.current === 0) {
|
|
17
|
+
lastExecutedRef.current = now;
|
|
18
|
+
if (leading) {
|
|
19
|
+
setThrottledValue(value);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (trailing && !timeoutRef.current) {
|
|
23
|
+
pendingValueRef.current = value;
|
|
24
|
+
timeoutRef.current = setTimeout(() => {
|
|
25
|
+
timeoutRef.current = null;
|
|
26
|
+
if (pendingValueRef.current !== null) {
|
|
27
|
+
setThrottledValue(pendingValueRef.current);
|
|
28
|
+
pendingValueRef.current = null;
|
|
29
|
+
lastExecutedRef.current = Date.now();
|
|
30
|
+
}
|
|
31
|
+
}, wait);
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const elapsed = now - lastExecutedRef.current;
|
|
36
|
+
if (elapsed >= wait && leading) {
|
|
37
|
+
setThrottledValue(value);
|
|
38
|
+
lastExecutedRef.current = now;
|
|
39
|
+
pendingValueRef.current = null;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (trailing) {
|
|
43
|
+
pendingValueRef.current = value;
|
|
44
|
+
if (!timeoutRef.current) {
|
|
45
|
+
const remaining = Math.max(wait - elapsed, 0);
|
|
46
|
+
timeoutRef.current = setTimeout(() => {
|
|
47
|
+
timeoutRef.current = null;
|
|
48
|
+
if (pendingValueRef.current !== null) {
|
|
49
|
+
setThrottledValue(pendingValueRef.current);
|
|
50
|
+
pendingValueRef.current = null;
|
|
51
|
+
lastExecutedRef.current = Date.now();
|
|
52
|
+
}
|
|
53
|
+
}, remaining);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, [leading, trailing, value, wait]);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
return () => {
|
|
59
|
+
if (timeoutRef.current) {
|
|
60
|
+
clearTimeout(timeoutRef.current);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}, []);
|
|
64
|
+
return throttledValue;
|
|
65
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
export function useThrottle(value, interval, options = {}) {
|
|
3
|
+
const leading = options.leading ?? true;
|
|
4
|
+
const trailing = options.trailing ?? true;
|
|
5
|
+
const wait = Math.max(0, interval);
|
|
6
|
+
const [throttledValue, setThrottledValue] = useState(value);
|
|
7
|
+
const lastExecutedRef = useRef(0);
|
|
8
|
+
const timeoutRef = useRef(null);
|
|
9
|
+
const pendingValueRef = useRef(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (wait === 0) {
|
|
12
|
+
setThrottledValue(value);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const now = Date.now();
|
|
16
|
+
if (lastExecutedRef.current === 0) {
|
|
17
|
+
lastExecutedRef.current = now;
|
|
18
|
+
if (leading) {
|
|
19
|
+
setThrottledValue(value);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (trailing && !timeoutRef.current) {
|
|
23
|
+
pendingValueRef.current = value;
|
|
24
|
+
timeoutRef.current = setTimeout(() => {
|
|
25
|
+
timeoutRef.current = null;
|
|
26
|
+
if (pendingValueRef.current !== null) {
|
|
27
|
+
setThrottledValue(pendingValueRef.current);
|
|
28
|
+
pendingValueRef.current = null;
|
|
29
|
+
lastExecutedRef.current = Date.now();
|
|
30
|
+
}
|
|
31
|
+
}, wait);
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const elapsed = now - lastExecutedRef.current;
|
|
36
|
+
if (elapsed >= wait && leading) {
|
|
37
|
+
setThrottledValue(value);
|
|
38
|
+
lastExecutedRef.current = now;
|
|
39
|
+
pendingValueRef.current = null;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (trailing) {
|
|
43
|
+
pendingValueRef.current = value;
|
|
44
|
+
if (!timeoutRef.current) {
|
|
45
|
+
const remaining = Math.max(wait - elapsed, 0);
|
|
46
|
+
timeoutRef.current = setTimeout(() => {
|
|
47
|
+
timeoutRef.current = null;
|
|
48
|
+
if (pendingValueRef.current !== null) {
|
|
49
|
+
setThrottledValue(pendingValueRef.current);
|
|
50
|
+
pendingValueRef.current = null;
|
|
51
|
+
lastExecutedRef.current = Date.now();
|
|
52
|
+
}
|
|
53
|
+
}, remaining);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, [leading, trailing, value, wait]);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
return () => {
|
|
59
|
+
if (timeoutRef.current) {
|
|
60
|
+
clearTimeout(timeoutRef.current);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}, []);
|
|
64
|
+
return throttledValue;
|
|
65
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { useBoolean } from "../core/useBoolean.js";
|
|
2
|
+
export { useDebounceCallback } from "../core/useDebounceCallback.js";
|
|
3
|
+
export { useDebounceValue } from "../core/useDebounceValue.js";
|
|
4
|
+
export { useLocalStorage } from "../core/useLocalStorage.js";
|
|
5
|
+
export { useSessionStorage } from "../core/useSessionStorage.js";
|
|
6
|
+
export { useOnClickOutside } from "../core/useOnClickOutside.js";
|
|
7
|
+
export { useMediaQuery } from "../core/useMediaQuery.js";
|
|
8
|
+
export { useEventListener } from "../core/useEventListener.js";
|
|
9
|
+
export { useIsClient } from "../core/useIsClient.js";
|
|
10
|
+
export { useCopyToClipboard } from "../core/useCopyToClipboard.js";
|
|
11
|
+
export { usePrevious } from "../core/usePrevious.js";
|
|
12
|
+
export { useThrottle } from "../core/useThrottle.js";
|
|
13
|
+
export { useResizeObserver } from "../core/useResizeObserver.js";
|
|
14
|
+
export { useHover } from "../core/useHover.js";
|
|
15
|
+
export { useIsomorphicLayoutEffect } from "../core/useIsomorphicLayoutEffect.js";
|
|
16
|
+
export { useMap } from "../core/useMap.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { useBoolean } from "../core/useBoolean.js";
|
|
2
|
+
export type { UseBooleanResult } from "../core/useBoolean.js";
|
|
3
|
+
export { useDebounceCallback } from "../core/useDebounceCallback.js";
|
|
4
|
+
export type { DebounceOptions, DebouncedCallback } from "../core/useDebounceCallback.js";
|
|
5
|
+
export { useDebounceValue } from "../core/useDebounceValue.js";
|
|
6
|
+
export { useLocalStorage } from "../core/useLocalStorage.js";
|
|
7
|
+
export type { StorageOptions } from "../core/useLocalStorage.js";
|
|
8
|
+
export { useSessionStorage } from "../core/useSessionStorage.js";
|
|
9
|
+
export type { SessionStorageOptions } from "../core/useSessionStorage.js";
|
|
10
|
+
export { useOnClickOutside } from "../core/useOnClickOutside.js";
|
|
11
|
+
export { useMediaQuery } from "../core/useMediaQuery.js";
|
|
12
|
+
export type { UseMediaQueryOptions } from "../core/useMediaQuery.js";
|
|
13
|
+
export { useEventListener } from "../core/useEventListener.js";
|
|
14
|
+
export { useIsClient } from "../core/useIsClient.js";
|
|
15
|
+
export { useCopyToClipboard } from "../core/useCopyToClipboard.js";
|
|
16
|
+
export type { UseCopyToClipboardOptions, CopyToClipboardResult, } from "../core/useCopyToClipboard.js";
|
|
17
|
+
export { usePrevious } from "../core/usePrevious.js";
|
|
18
|
+
export { useThrottle } from "../core/useThrottle.js";
|
|
19
|
+
export type { ThrottleOptions } from "../core/useThrottle.js";
|
|
20
|
+
export { useResizeObserver } from "../core/useResizeObserver.js";
|
|
21
|
+
export { useHover } from "../core/useHover.js";
|
|
22
|
+
export { useIsomorphicLayoutEffect } from "../core/useIsomorphicLayoutEffect.js";
|
|
23
|
+
export { useMap } from "../core/useMap.js";
|
|
24
|
+
export type { MapActions } from "../core/useMap.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { useBoolean } from "../core/useBoolean.js";
|
|
2
|
+
export { useDebounceCallback } from "../core/useDebounceCallback.js";
|
|
3
|
+
export { useDebounceValue } from "../core/useDebounceValue.js";
|
|
4
|
+
export { useLocalStorage } from "../core/useLocalStorage.js";
|
|
5
|
+
export { useSessionStorage } from "../core/useSessionStorage.js";
|
|
6
|
+
export { useOnClickOutside } from "../core/useOnClickOutside.js";
|
|
7
|
+
export { useMediaQuery } from "../core/useMediaQuery.js";
|
|
8
|
+
export { useEventListener } from "../core/useEventListener.js";
|
|
9
|
+
export { useIsClient } from "../core/useIsClient.js";
|
|
10
|
+
export { useCopyToClipboard } from "../core/useCopyToClipboard.js";
|
|
11
|
+
export { usePrevious } from "../core/usePrevious.js";
|
|
12
|
+
export { useThrottle } from "../core/useThrottle.js";
|
|
13
|
+
export { useResizeObserver } from "../core/useResizeObserver.js";
|
|
14
|
+
export { useHover } from "../core/useHover.js";
|
|
15
|
+
export { useIsomorphicLayoutEffect } from "../core/useIsomorphicLayoutEffect.js";
|
|
16
|
+
export { useMap } from "../core/useMap.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useBoolean } from "../core/useBoolean.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useBoolean } from "../core/useBoolean.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useCopyToClipboard } from "../core/useCopyToClipboard.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useCopyToClipboard } from "../core/useCopyToClipboard.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useDebounceCallback } from "../core/useDebounceCallback.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useDebounceCallback } from "../core/useDebounceCallback.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useDebounceValue } from "../core/useDebounceValue.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useDebounceValue } from "../core/useDebounceValue.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useEventListener } from "../core/useEventListener.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useEventListener } from "../core/useEventListener.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useEventListener } from "../core/useEventListener.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useHover } from "../core/useHover.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useHover } from "../core/useHover.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useHover } from "../core/useHover.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useIsClient } from "../core/useIsClient.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useIsClient } from "../core/useIsClient.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useIsClient } from "../core/useIsClient.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useIsomorphicLayoutEffect } from "../core/useIsomorphicLayoutEffect.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useIsomorphicLayoutEffect } from "../core/useIsomorphicLayoutEffect.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useIsomorphicLayoutEffect } from "../core/useIsomorphicLayoutEffect.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useLocalStorage } from "../core/useLocalStorage.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useLocalStorage } from "../core/useLocalStorage.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMap } from "../core/useMap.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMap } from "../core/useMap.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMediaQuery } from "../core/useMediaQuery.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMediaQuery } from "../core/useMediaQuery.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useOnClickOutside } from "../core/useOnClickOutside.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useOnClickOutside } from "../core/useOnClickOutside.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useOnClickOutside } from "../core/useOnClickOutside.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { usePrevious } from "../core/usePrevious.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { usePrevious } from "../core/usePrevious.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { usePrevious } from "../core/usePrevious.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useResizeObserver } from "../core/useResizeObserver.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useResizeObserver } from "../core/useResizeObserver.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useResizeObserver } from "../core/useResizeObserver.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSessionStorage } from "../core/useSessionStorage.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSessionStorage } from "../core/useSessionStorage.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useThrottle } from "../core/useThrottle.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useThrottle } from "../core/useThrottle.js";
|
package/dist/index.cjs
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED