react-simplikit 0.0.50 → 0.0.52
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/components/ImpressionArea/ImpressionArea.cjs +57 -0
- package/{esm/components/ImpressionArea/index.d.ts → dist/components/ImpressionArea/ImpressionArea.d.cts} +9 -8
- package/dist/components/ImpressionArea/ImpressionArea.d.mts +48 -0
- package/dist/components/ImpressionArea/ImpressionArea.mjs +57 -0
- package/dist/components/ImpressionArea/index.d.cts +2 -46
- package/dist/components/ImpressionArea/index.d.mts +3 -0
- package/dist/components/Separated/Separated.cjs +38 -0
- package/{esm/components/Separated/index.d.ts → dist/components/Separated/Separated.d.cts} +7 -7
- package/dist/components/Separated/Separated.d.mts +38 -0
- package/dist/components/Separated/Separated.mjs +38 -0
- package/dist/components/Separated/index.d.cts +2 -37
- package/dist/components/Separated/index.d.mts +3 -0
- package/dist/components/SwitchCase/SwitchCase.cjs +40 -0
- package/{esm/components/SwitchCase/index.d.ts → dist/components/SwitchCase/SwitchCase.d.cts} +7 -8
- package/dist/components/SwitchCase/SwitchCase.d.mts +45 -0
- package/dist/components/SwitchCase/SwitchCase.mjs +40 -0
- package/dist/components/SwitchCase/index.d.cts +2 -45
- package/dist/components/SwitchCase/index.d.mts +3 -0
- package/dist/hooks/useAsyncEffect/index.d.cts +2 -24
- package/dist/hooks/useAsyncEffect/index.d.mts +3 -0
- package/dist/hooks/useAsyncEffect/useAsyncEffect.cjs +39 -0
- package/{esm/hooks/useAsyncEffect/index.d.ts → dist/hooks/useAsyncEffect/useAsyncEffect.d.cts} +4 -3
- package/dist/hooks/useAsyncEffect/useAsyncEffect.d.mts +26 -0
- package/dist/hooks/useAsyncEffect/useAsyncEffect.mjs +39 -0
- package/dist/hooks/useBooleanState/useBooleanState.cjs +36 -0
- package/dist/hooks/useBooleanState/{index.d.cts → useBooleanState.d.cts} +4 -2
- package/{esm/hooks/useBooleanState/index.d.ts → dist/hooks/useBooleanState/useBooleanState.d.mts} +4 -2
- package/dist/hooks/useBooleanState/useBooleanState.mjs +36 -0
- package/dist/hooks/useCallbackOncePerRender/index.d.cts +2 -39
- package/dist/hooks/useCallbackOncePerRender/index.d.mts +3 -0
- package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.cjs +52 -0
- package/{esm/hooks/useCallbackOncePerRender/index.d.ts → dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.d.cts} +4 -3
- package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.d.mts +41 -0
- package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.mjs +52 -0
- package/dist/hooks/useConditionalEffect/index.d.cts +2 -42
- package/dist/hooks/useConditionalEffect/index.d.mts +3 -0
- package/dist/hooks/useConditionalEffect/useConditionalEffect.cjs +57 -0
- package/{esm/hooks/useConditionalEffect/index.d.ts → dist/hooks/useConditionalEffect/useConditionalEffect.d.cts} +4 -3
- package/dist/hooks/useConditionalEffect/useConditionalEffect.d.mts +44 -0
- package/dist/hooks/useConditionalEffect/useConditionalEffect.mjs +57 -0
- package/dist/hooks/useControlledState/index.d.cts +2 -50
- package/dist/hooks/useControlledState/index.d.mts +3 -0
- package/dist/hooks/useControlledState/useControlledState.cjs +60 -0
- package/{esm/hooks/useControlledState/index.d.ts → dist/hooks/useControlledState/useControlledState.d.cts} +11 -10
- package/dist/hooks/useControlledState/useControlledState.d.mts +52 -0
- package/dist/hooks/useControlledState/useControlledState.mjs +60 -0
- package/dist/hooks/useCounter/useCounter.cjs +75 -0
- package/{esm/hooks/useCounter/index.d.ts → dist/hooks/useCounter/useCounter.d.cts} +12 -10
- package/dist/hooks/useCounter/{index.d.cts → useCounter.d.mts} +12 -10
- package/dist/hooks/useCounter/useCounter.mjs +75 -0
- package/dist/hooks/useDebounce/debounce.cjs +49 -0
- package/dist/hooks/useDebounce/debounce.d.cts +8 -0
- package/dist/hooks/useDebounce/debounce.d.mts +8 -0
- package/dist/hooks/useDebounce/debounce.mjs +49 -0
- package/dist/hooks/useDebounce/useDebounce.cjs +66 -0
- package/{esm/hooks/useDebounce/index.d.ts → dist/hooks/useDebounce/useDebounce.d.cts} +6 -8
- package/dist/hooks/useDebounce/{index.d.cts → useDebounce.d.mts} +6 -8
- package/dist/hooks/useDebounce/useDebounce.mjs +66 -0
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.cjs +62 -0
- package/{esm/hooks/useDebouncedCallback/index.d.ts → dist/hooks/useDebouncedCallback/useDebouncedCallback.d.cts} +9 -7
- package/dist/hooks/useDebouncedCallback/{index.d.cts → useDebouncedCallback.d.mts} +9 -7
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.mjs +62 -0
- package/dist/hooks/useDoubleClick/index.d.cts +2 -45
- package/dist/hooks/useDoubleClick/index.d.mts +3 -0
- package/dist/hooks/useDoubleClick/useDoubleClick.cjs +64 -0
- package/{esm/hooks/useDoubleClick/index.d.ts → dist/hooks/useDoubleClick/useDoubleClick.d.cts} +8 -7
- package/dist/hooks/useDoubleClick/useDoubleClick.d.mts +47 -0
- package/dist/hooks/useDoubleClick/useDoubleClick.mjs +64 -0
- package/dist/hooks/useGeolocation/useGeolocation.cjs +210 -0
- package/{esm/hooks/useGeolocation/index.d.ts → dist/hooks/useGeolocation/useGeolocation.d.cts} +26 -24
- package/dist/hooks/useGeolocation/{index.d.cts → useGeolocation.d.mts} +26 -24
- package/dist/hooks/useGeolocation/useGeolocation.mjs +209 -0
- package/dist/hooks/useImpressionRef/useImpressionRef.cjs +67 -0
- package/{esm/hooks/useImpressionRef/index.d.ts → dist/hooks/useImpressionRef/useImpressionRef.d.cts} +10 -8
- package/dist/hooks/useImpressionRef/{index.d.cts → useImpressionRef.d.mts} +10 -8
- package/dist/hooks/useImpressionRef/useImpressionRef.mjs +67 -0
- package/dist/hooks/useInputState/index.d.cts +2 -22
- package/dist/hooks/useInputState/index.d.mts +3 -0
- package/dist/hooks/useInputState/useInputState.cjs +32 -0
- package/{esm/hooks/useInputState/index.d.ts → dist/hooks/useInputState/useInputState.d.cts} +4 -3
- package/dist/hooks/useInputState/useInputState.d.mts +24 -0
- package/dist/hooks/useInputState/useInputState.mjs +32 -0
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.cjs +58 -0
- package/dist/hooks/useIntersectionObserver/{index.d.cts → useIntersectionObserver.d.cts} +4 -2
- package/{esm/hooks/useIntersectionObserver/index.d.ts → dist/hooks/useIntersectionObserver/useIntersectionObserver.d.mts} +4 -2
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.mjs +58 -0
- package/dist/hooks/useInterval/useInterval.cjs +65 -0
- package/dist/hooks/useInterval/{index.d.cts → useInterval.d.cts} +7 -5
- package/{esm/hooks/useInterval/index.d.ts → dist/hooks/useInterval/useInterval.d.mts} +7 -5
- package/dist/hooks/useInterval/useInterval.mjs +65 -0
- package/dist/hooks/useIsClient/useIsClient.cjs +49 -0
- package/dist/hooks/useIsClient/{index.d.cts → useIsClient.d.cts} +4 -2
- package/{esm/hooks/useIsClient/index.d.ts → dist/hooks/useIsClient/useIsClient.d.mts} +4 -2
- package/dist/hooks/useIsClient/useIsClient.mjs +49 -0
- package/dist/hooks/useIsomorphicLayoutEffect/index.d.cts +2 -24
- package/dist/hooks/useIsomorphicLayoutEffect/index.d.mts +3 -0
- package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs +25 -0
- package/{esm/hooks/useIsomorphicLayoutEffect/index.d.ts → dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.cts} +4 -3
- package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.mts +26 -0
- package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs +25 -0
- package/dist/hooks/useList/useList.cjs +94 -0
- package/{esm/hooks/useList/index.d.ts → dist/hooks/useList/useList.d.cts} +10 -8
- package/dist/hooks/useList/{index.d.cts → useList.d.mts} +10 -8
- package/dist/hooks/useList/useList.mjs +94 -0
- package/dist/hooks/useLoading/useLoading.cjs +61 -0
- package/dist/hooks/useLoading/{index.d.cts → useLoading.d.cts} +4 -2
- package/{esm/hooks/useLoading/index.d.ts → dist/hooks/useLoading/useLoading.d.mts} +4 -2
- package/dist/hooks/useLoading/useLoading.mjs +61 -0
- package/dist/hooks/useLongPress/index.d.cts +2 -73
- package/dist/hooks/useLongPress/index.d.mts +3 -0
- package/dist/hooks/useLongPress/useLongPress.cjs +133 -0
- package/{esm/hooks/useLongPress/index.d.ts → dist/hooks/useLongPress/useLongPress.d.cts} +18 -17
- package/dist/hooks/useLongPress/useLongPress.d.mts +75 -0
- package/dist/hooks/useLongPress/useLongPress.mjs +133 -0
- package/dist/hooks/useMap/useMap.cjs +64 -0
- package/dist/hooks/useMap/{index.d.cts → useMap.d.cts} +12 -10
- package/{esm/hooks/useMap/index.d.ts → dist/hooks/useMap/useMap.d.mts} +12 -10
- package/dist/hooks/useMap/useMap.mjs +64 -0
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.cjs +51 -0
- package/{esm/hooks/useOutsideClickEffect/index.d.ts → dist/hooks/useOutsideClickEffect/useOutsideClickEffect.d.cts} +4 -2
- package/dist/hooks/useOutsideClickEffect/{index.d.cts → useOutsideClickEffect.d.mts} +4 -2
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.mjs +51 -0
- package/dist/hooks/usePreservedCallback/usePreservedCallback.cjs +41 -0
- package/dist/hooks/usePreservedCallback/{index.d.cts → usePreservedCallback.d.cts} +4 -2
- package/{esm/hooks/usePreservedCallback/index.d.ts → dist/hooks/usePreservedCallback/usePreservedCallback.d.mts} +4 -2
- package/dist/hooks/usePreservedCallback/usePreservedCallback.mjs +41 -0
- package/dist/hooks/usePreservedReference/usePreservedReference.cjs +55 -0
- package/dist/hooks/usePreservedReference/{index.d.cts → usePreservedReference.d.cts} +4 -2
- package/{esm/hooks/usePreservedReference/index.d.ts → dist/hooks/usePreservedReference/usePreservedReference.d.mts} +4 -2
- package/dist/hooks/usePreservedReference/usePreservedReference.mjs +55 -0
- package/dist/hooks/usePrevious/usePrevious.cjs +38 -0
- package/{esm/hooks/usePrevious/index.d.ts → dist/hooks/usePrevious/usePrevious.d.cts} +4 -2
- package/dist/hooks/usePrevious/{index.d.cts → usePrevious.d.mts} +4 -2
- package/dist/hooks/usePrevious/usePrevious.mjs +38 -0
- package/dist/hooks/useRefEffect/index.d.cts +2 -30
- package/dist/hooks/useRefEffect/index.d.mts +3 -0
- package/dist/hooks/useRefEffect/useRefEffect.cjs +42 -0
- package/{esm/hooks/useRefEffect/index.d.ts → dist/hooks/useRefEffect/useRefEffect.d.cts} +4 -3
- package/dist/hooks/useRefEffect/useRefEffect.d.mts +32 -0
- package/dist/hooks/useRefEffect/useRefEffect.mjs +42 -0
- package/dist/hooks/useSet/useSet.cjs +79 -0
- package/dist/hooks/useSet/{index.d.cts → useSet.d.cts} +9 -7
- package/{esm/hooks/useSet/index.d.ts → dist/hooks/useSet/useSet.d.mts} +9 -7
- package/dist/hooks/useSet/useSet.mjs +79 -0
- package/dist/hooks/useStorageState/index.d.cts +2 -60
- package/dist/hooks/useStorageState/index.d.mts +3 -0
- package/dist/hooks/useStorageState/storage.cjs +85 -0
- package/dist/hooks/useStorageState/storage.d.cts +10 -0
- package/dist/hooks/useStorageState/storage.d.mts +10 -0
- package/dist/hooks/useStorageState/storage.mjs +80 -0
- package/dist/hooks/useStorageState/useStorageState.cjs +81 -0
- package/{esm/hooks/useStorageState/index.d.ts → dist/hooks/useStorageState/useStorageState.d.cts} +10 -15
- package/dist/hooks/useStorageState/useStorageState.d.mts +56 -0
- package/dist/hooks/useStorageState/useStorageState.mjs +81 -0
- package/dist/hooks/useThrottle/throttle.cjs +19 -0
- package/dist/hooks/useThrottle/throttle.d.cts +19 -0
- package/dist/hooks/useThrottle/throttle.d.mts +19 -0
- package/dist/hooks/useThrottle/throttle.mjs +19 -0
- package/dist/hooks/useThrottle/useThrottle.cjs +49 -0
- package/dist/hooks/useThrottle/{index.d.cts → useThrottle.d.cts} +6 -19
- package/{esm/hooks/useThrottle/index.d.ts → dist/hooks/useThrottle/useThrottle.d.mts} +6 -19
- package/dist/hooks/useThrottle/useThrottle.mjs +49 -0
- package/dist/hooks/useThrottledCallback/useThrottledCallback.cjs +57 -0
- package/{esm/hooks/useThrottledCallback/index.d.ts → dist/hooks/useThrottledCallback/useThrottledCallback.d.cts} +8 -6
- package/dist/hooks/useThrottledCallback/{index.d.cts → useThrottledCallback.d.mts} +8 -6
- package/dist/hooks/useThrottledCallback/useThrottledCallback.mjs +57 -0
- package/dist/hooks/useTimeout/useTimeout.cjs +40 -0
- package/dist/hooks/useTimeout/{index.d.cts → useTimeout.d.cts} +4 -2
- package/{esm/hooks/useTimeout/index.d.ts → dist/hooks/useTimeout/useTimeout.d.mts} +4 -2
- package/dist/hooks/useTimeout/useTimeout.mjs +40 -0
- package/dist/hooks/useToggle/useToggle.cjs +34 -0
- package/dist/hooks/useToggle/{index.d.cts → useToggle.d.cts} +4 -4
- package/{esm/hooks/useToggle/index.d.ts → dist/hooks/useToggle/useToggle.d.mts} +4 -4
- package/dist/hooks/useToggle/useToggle.mjs +34 -0
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.cjs +42 -0
- package/{esm/hooks/useVisibilityEvent/index.d.ts → dist/hooks/useVisibilityEvent/useVisibilityEvent.d.cts} +5 -3
- package/dist/hooks/useVisibilityEvent/{index.d.cts → useVisibilityEvent.d.mts} +5 -3
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.mjs +42 -0
- package/dist/index.cjs +77 -1382
- package/dist/index.d.cts +56 -40
- package/dist/index.d.mts +56 -0
- package/dist/index.mjs +40 -0
- package/dist/utils/buildContext/buildContext.cjs +50 -0
- package/{esm/utils/buildContext/index.d.ts → dist/utils/buildContext/buildContext.d.cts} +7 -7
- package/dist/utils/buildContext/buildContext.d.mts +38 -0
- package/dist/utils/buildContext/buildContext.mjs +50 -0
- package/dist/utils/buildContext/index.d.cts +2 -37
- package/dist/utils/buildContext/index.d.mts +3 -0
- package/dist/utils/mergeProps/index.d.cts +2 -25
- package/dist/utils/mergeProps/index.d.mts +3 -0
- package/dist/utils/mergeProps/mergeProps.cjs +53 -0
- package/{esm/utils/mergeProps/index.d.ts → dist/utils/mergeProps/mergeProps.d.cts} +7 -8
- package/dist/utils/mergeProps/mergeProps.d.mts +25 -0
- package/dist/utils/mergeProps/mergeProps.mjs +53 -0
- package/dist/utils/mergeRefs/index.d.cts +2 -38
- package/dist/utils/mergeRefs/index.d.mts +3 -0
- package/dist/utils/mergeRefs/mergeRefs.cjs +50 -0
- package/{esm/utils/mergeRefs/index.d.ts → dist/utils/mergeRefs/mergeRefs.d.cts} +4 -3
- package/dist/utils/mergeRefs/mergeRefs.d.mts +40 -0
- package/dist/utils/mergeRefs/mergeRefs.mjs +50 -0
- package/package.json +9 -11
- package/dist/components/ImpressionArea/index.cjs +0 -295
- package/dist/components/Separated/index.cjs +0 -41
- package/dist/components/SwitchCase/index.cjs +0 -36
- package/dist/hooks/useAsyncEffect/index.cjs +0 -44
- package/dist/hooks/useBooleanState/index.cjs +0 -46
- package/dist/hooks/useCallbackOncePerRender/index.cjs +0 -63
- package/dist/hooks/useConditionalEffect/index.cjs +0 -51
- package/dist/hooks/useControlledState/index.cjs +0 -57
- package/dist/hooks/useCounter/index.cjs +0 -70
- package/dist/hooks/useDebounce/index.cjs +0 -130
- package/dist/hooks/useDebouncedCallback/index.cjs +0 -148
- package/dist/hooks/useDoubleClick/index.cjs +0 -79
- package/dist/hooks/useGeolocation/index.cjs +0 -154
- package/dist/hooks/useImpressionRef/index.cjs +0 -258
- package/dist/hooks/useInputState/index.cjs +0 -46
- package/dist/hooks/useIntersectionObserver/index.cjs +0 -95
- package/dist/hooks/useInterval/index.cjs +0 -74
- package/dist/hooks/useIsClient/index.cjs +0 -40
- package/dist/hooks/useIsomorphicLayoutEffect/index.cjs +0 -35
- package/dist/hooks/useList/index.cjs +0 -104
- package/dist/hooks/useLoading/index.cjs +0 -65
- package/dist/hooks/useLongPress/index.cjs +0 -127
- package/dist/hooks/useMap/index.cjs +0 -78
- package/dist/hooks/useOutsideClickEffect/index.cjs +0 -74
- package/dist/hooks/usePreservedCallback/index.cjs +0 -45
- package/dist/hooks/usePreservedReference/index.cjs +0 -45
- package/dist/hooks/usePrevious/index.cjs +0 -48
- package/dist/hooks/useRefEffect/index.cjs +0 -72
- package/dist/hooks/useSet/index.cjs +0 -105
- package/dist/hooks/useStorageState/index.cjs +0 -196
- package/dist/hooks/useThrottle/index.cjs +0 -151
- package/dist/hooks/useThrottledCallback/index.cjs +0 -172
- package/dist/hooks/useTimeout/index.cjs +0 -57
- package/dist/hooks/useToggle/index.cjs +0 -37
- package/dist/hooks/useVisibilityEvent/index.cjs +0 -47
- package/dist/utils/buildContext/index.cjs +0 -56
- package/dist/utils/mergeProps/index.cjs +0 -71
- package/dist/utils/mergeRefs/index.cjs +0 -46
- package/esm/components/ImpressionArea/index.js +0 -269
- package/esm/components/Separated/index.js +0 -15
- package/esm/components/SwitchCase/index.js +0 -10
- package/esm/hooks/useAsyncEffect/index.js +0 -18
- package/esm/hooks/useBooleanState/index.js +0 -20
- package/esm/hooks/useCallbackOncePerRender/index.js +0 -37
- package/esm/hooks/useConditionalEffect/index.js +0 -25
- package/esm/hooks/useControlledState/index.js +0 -31
- package/esm/hooks/useCounter/index.js +0 -44
- package/esm/hooks/useDebounce/index.js +0 -104
- package/esm/hooks/useDebouncedCallback/index.js +0 -122
- package/esm/hooks/useDoubleClick/index.js +0 -53
- package/esm/hooks/useGeolocation/index.js +0 -128
- package/esm/hooks/useImpressionRef/index.js +0 -232
- package/esm/hooks/useInputState/index.js +0 -20
- package/esm/hooks/useIntersectionObserver/index.js +0 -69
- package/esm/hooks/useInterval/index.js +0 -48
- package/esm/hooks/useIsClient/index.js +0 -14
- package/esm/hooks/useIsomorphicLayoutEffect/index.js +0 -9
- package/esm/hooks/useList/index.js +0 -78
- package/esm/hooks/useLoading/index.js +0 -39
- package/esm/hooks/useLongPress/index.js +0 -101
- package/esm/hooks/useMap/index.js +0 -52
- package/esm/hooks/useOutsideClickEffect/index.js +0 -48
- package/esm/hooks/usePreservedCallback/index.js +0 -19
- package/esm/hooks/usePreservedReference/index.js +0 -19
- package/esm/hooks/usePrevious/index.js +0 -22
- package/esm/hooks/useRefEffect/index.js +0 -46
- package/esm/hooks/useSet/index.js +0 -79
- package/esm/hooks/useStorageState/index.js +0 -170
- package/esm/hooks/useThrottle/index.js +0 -125
- package/esm/hooks/useThrottledCallback/index.js +0 -146
- package/esm/hooks/useTimeout/index.js +0 -31
- package/esm/hooks/useToggle/index.js +0 -11
- package/esm/hooks/useVisibilityEvent/index.js +0 -21
- package/esm/index.d.ts +0 -40
- package/esm/index.js +0 -1320
- package/esm/utils/buildContext/index.js +0 -30
- package/esm/utils/mergeProps/index.js +0 -45
- package/esm/utils/mergeRefs/index.js +0 -20
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* `useIsomorphicLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering.
|
|
6
|
-
* During SSR, there is no DOM to synchronously measure or mutate, so React warns about using `useLayoutEffect`.
|
|
7
|
-
*
|
|
8
|
-
* This hook runs synchronously after DOM updates but before paint, making it ideal for:
|
|
9
|
-
*
|
|
10
|
-
* - Measuring DOM elements after render
|
|
11
|
-
* - Applying DOM changes before paint
|
|
12
|
-
* - Preventing UI flashes or layout shifts
|
|
13
|
-
* - Supporting both client and server environments safely
|
|
14
|
-
*
|
|
15
|
-
* @param {React.EffectCallback} effect - The effect function.
|
|
16
|
-
* @param {React.DependencyList} [deps] - An optional array of dependencies.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* useIsomorphicLayoutEffect(() => {
|
|
20
|
-
* // Code to be executed during the layout phase on the client side
|
|
21
|
-
* }, [dep1, dep2, ...]);
|
|
22
|
-
*/
|
|
23
|
-
declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
24
|
-
|
|
25
|
-
export { useIsomorphicLayoutEffect };
|
|
2
|
+
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.cjs";
|
|
3
|
+
export { useIsomorphicLayoutEffect };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
let react = require("react");
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* `useIsomorphicLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering.
|
|
6
|
+
* During SSR, there is no DOM to synchronously measure or mutate, so React warns about using `useLayoutEffect`.
|
|
7
|
+
*
|
|
8
|
+
* This hook runs synchronously after DOM updates but before paint, making it ideal for:
|
|
9
|
+
*
|
|
10
|
+
* - Measuring DOM elements after render
|
|
11
|
+
* - Applying DOM changes before paint
|
|
12
|
+
* - Preventing UI flashes or layout shifts
|
|
13
|
+
* - Supporting both client and server environments safely
|
|
14
|
+
*
|
|
15
|
+
* @param {React.EffectCallback} effect - The effect function.
|
|
16
|
+
* @param {React.DependencyList} [deps] - An optional array of dependencies.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* useIsomorphicLayoutEffect(() => {
|
|
20
|
+
* // Code to be executed during the layout phase on the client side
|
|
21
|
+
* }, [dep1, dep2, ...]);
|
|
22
|
+
*/
|
|
23
|
+
const useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
1
|
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
//#region src/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* @description
|
|
5
6
|
* `useIsomorphicLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering.
|
|
@@ -21,5 +22,5 @@ import { useEffect } from 'react';
|
|
|
21
22
|
* }, [dep1, dep2, ...]);
|
|
22
23
|
*/
|
|
23
24
|
declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
24
|
-
|
|
25
|
-
export { useIsomorphicLayoutEffect };
|
|
25
|
+
//#endregion
|
|
26
|
+
export { useIsomorphicLayoutEffect };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
//#region src/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* `useIsomorphicLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering.
|
|
7
|
+
* During SSR, there is no DOM to synchronously measure or mutate, so React warns about using `useLayoutEffect`.
|
|
8
|
+
*
|
|
9
|
+
* This hook runs synchronously after DOM updates but before paint, making it ideal for:
|
|
10
|
+
*
|
|
11
|
+
* - Measuring DOM elements after render
|
|
12
|
+
* - Applying DOM changes before paint
|
|
13
|
+
* - Preventing UI flashes or layout shifts
|
|
14
|
+
* - Supporting both client and server environments safely
|
|
15
|
+
*
|
|
16
|
+
* @param {React.EffectCallback} effect - The effect function.
|
|
17
|
+
* @param {React.DependencyList} [deps] - An optional array of dependencies.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* useIsomorphicLayoutEffect(() => {
|
|
21
|
+
* // Code to be executed during the layout phase on the client side
|
|
22
|
+
* }, [dep1, dep2, ...]);
|
|
23
|
+
*/
|
|
24
|
+
declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { useIsomorphicLayoutEffect };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useLayoutEffect } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* `useIsomorphicLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering.
|
|
6
|
+
* During SSR, there is no DOM to synchronously measure or mutate, so React warns about using `useLayoutEffect`.
|
|
7
|
+
*
|
|
8
|
+
* This hook runs synchronously after DOM updates but before paint, making it ideal for:
|
|
9
|
+
*
|
|
10
|
+
* - Measuring DOM elements after render
|
|
11
|
+
* - Applying DOM changes before paint
|
|
12
|
+
* - Preventing UI flashes or layout shifts
|
|
13
|
+
* - Supporting both client and server environments safely
|
|
14
|
+
*
|
|
15
|
+
* @param {React.EffectCallback} effect - The effect function.
|
|
16
|
+
* @param {React.DependencyList} [deps] - An optional array of dependencies.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* useIsomorphicLayoutEffect(() => {
|
|
20
|
+
* // Code to be executed during the layout phase on the client side
|
|
21
|
+
* }, [dep1, dep2, ...]);
|
|
22
|
+
*/
|
|
23
|
+
const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { useIsomorphicLayoutEffect };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const require_usePreservedCallback = require("../usePreservedCallback/usePreservedCallback.cjs");
|
|
3
|
+
const require_usePreservedReference = require("../usePreservedReference/usePreservedReference.cjs");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
//#region src/hooks/useList/useList.ts
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* A React hook that manages an array as state.
|
|
9
|
+
* Provides efficient state management and stable action functions.
|
|
10
|
+
*
|
|
11
|
+
* @param {T[]} initialState - Initial array state
|
|
12
|
+
*
|
|
13
|
+
* @returns {UseListReturn<T>} A tuple containing the array state and actions to manipulate it
|
|
14
|
+
* - `push` - Appends a value to the end of the list
|
|
15
|
+
* - `insertAt` - Inserts a value at the specified index
|
|
16
|
+
* - `updateAt` - Updates the value at the specified index
|
|
17
|
+
* - `removeAt` - Removes the value at the specified index
|
|
18
|
+
* - `setAll` - Replaces the entire list with a new array
|
|
19
|
+
* - `reset` - Resets the list to its initial state
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const [list, actions] = useList<string>(['apple', 'banana']);
|
|
24
|
+
*
|
|
25
|
+
* // Add an item
|
|
26
|
+
* actions.push('cherry');
|
|
27
|
+
*
|
|
28
|
+
* // Insert at index
|
|
29
|
+
* actions.insertAt(1, 'grape');
|
|
30
|
+
*
|
|
31
|
+
* // Update at index
|
|
32
|
+
* actions.updateAt(0, 'orange');
|
|
33
|
+
*
|
|
34
|
+
* // Remove at index
|
|
35
|
+
* actions.removeAt(2);
|
|
36
|
+
*
|
|
37
|
+
* // Replace all
|
|
38
|
+
* actions.setAll(['kiwi', 'mango']);
|
|
39
|
+
*
|
|
40
|
+
* // Reset to initial state
|
|
41
|
+
* actions.reset();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function useList(initialState = []) {
|
|
45
|
+
const [list, setList] = (0, react.useState)(initialState);
|
|
46
|
+
const preservedInitialState = require_usePreservedReference.usePreservedReference(initialState);
|
|
47
|
+
const push = require_usePreservedCallback.usePreservedCallback((value) => {
|
|
48
|
+
setList((prev) => [...prev, value]);
|
|
49
|
+
});
|
|
50
|
+
const insertAt = require_usePreservedCallback.usePreservedCallback((index, value) => {
|
|
51
|
+
setList((prev) => {
|
|
52
|
+
const next = [...prev];
|
|
53
|
+
next.splice(index, 0, value);
|
|
54
|
+
return next;
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
const updateAt = require_usePreservedCallback.usePreservedCallback((index, value) => {
|
|
58
|
+
setList((prev) => {
|
|
59
|
+
const next = [...prev];
|
|
60
|
+
next[index] = value;
|
|
61
|
+
return next;
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
const removeAt = require_usePreservedCallback.usePreservedCallback((index) => {
|
|
65
|
+
setList((prev) => {
|
|
66
|
+
const next = [...prev];
|
|
67
|
+
next.splice(index, 1);
|
|
68
|
+
return next;
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
const setAll = require_usePreservedCallback.usePreservedCallback((values) => {
|
|
72
|
+
setList(values);
|
|
73
|
+
});
|
|
74
|
+
const reset = require_usePreservedCallback.usePreservedCallback(() => {
|
|
75
|
+
setList(preservedInitialState);
|
|
76
|
+
});
|
|
77
|
+
return [list, (0, react.useMemo)(() => ({
|
|
78
|
+
push,
|
|
79
|
+
insertAt,
|
|
80
|
+
updateAt,
|
|
81
|
+
removeAt,
|
|
82
|
+
setAll,
|
|
83
|
+
reset
|
|
84
|
+
}), [
|
|
85
|
+
push,
|
|
86
|
+
insertAt,
|
|
87
|
+
updateAt,
|
|
88
|
+
removeAt,
|
|
89
|
+
setAll,
|
|
90
|
+
reset
|
|
91
|
+
])];
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
exports.useList = useList;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/hooks/useList/useList.d.ts
|
|
1
3
|
type ListActions<T> = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
push: (value: T) => void;
|
|
5
|
+
insertAt: (index: number, value: T) => void;
|
|
6
|
+
updateAt: (index: number, value: T) => void;
|
|
7
|
+
removeAt: (index: number) => void;
|
|
8
|
+
setAll: (values: T[]) => void;
|
|
9
|
+
reset: () => void;
|
|
8
10
|
};
|
|
9
11
|
type UseListReturn<T> = [ReadonlyArray<T>, ListActions<T>];
|
|
10
12
|
/**
|
|
@@ -46,5 +48,5 @@ type UseListReturn<T> = [ReadonlyArray<T>, ListActions<T>];
|
|
|
46
48
|
* ```
|
|
47
49
|
*/
|
|
48
50
|
declare function useList<T>(initialState?: T[]): UseListReturn<T>;
|
|
49
|
-
|
|
50
|
-
export { useList };
|
|
51
|
+
//#endregion
|
|
52
|
+
export { useList };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/hooks/useList/useList.d.ts
|
|
1
3
|
type ListActions<T> = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
push: (value: T) => void;
|
|
5
|
+
insertAt: (index: number, value: T) => void;
|
|
6
|
+
updateAt: (index: number, value: T) => void;
|
|
7
|
+
removeAt: (index: number) => void;
|
|
8
|
+
setAll: (values: T[]) => void;
|
|
9
|
+
reset: () => void;
|
|
8
10
|
};
|
|
9
11
|
type UseListReturn<T> = [ReadonlyArray<T>, ListActions<T>];
|
|
10
12
|
/**
|
|
@@ -46,5 +48,5 @@ type UseListReturn<T> = [ReadonlyArray<T>, ListActions<T>];
|
|
|
46
48
|
* ```
|
|
47
49
|
*/
|
|
48
50
|
declare function useList<T>(initialState?: T[]): UseListReturn<T>;
|
|
49
|
-
|
|
50
|
-
export { useList };
|
|
51
|
+
//#endregion
|
|
52
|
+
export { useList };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { usePreservedCallback } from "../usePreservedCallback/usePreservedCallback.mjs";
|
|
3
|
+
import { usePreservedReference } from "../usePreservedReference/usePreservedReference.mjs";
|
|
4
|
+
import { useMemo, useState } from "react";
|
|
5
|
+
//#region src/hooks/useList/useList.ts
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* A React hook that manages an array as state.
|
|
9
|
+
* Provides efficient state management and stable action functions.
|
|
10
|
+
*
|
|
11
|
+
* @param {T[]} initialState - Initial array state
|
|
12
|
+
*
|
|
13
|
+
* @returns {UseListReturn<T>} A tuple containing the array state and actions to manipulate it
|
|
14
|
+
* - `push` - Appends a value to the end of the list
|
|
15
|
+
* - `insertAt` - Inserts a value at the specified index
|
|
16
|
+
* - `updateAt` - Updates the value at the specified index
|
|
17
|
+
* - `removeAt` - Removes the value at the specified index
|
|
18
|
+
* - `setAll` - Replaces the entire list with a new array
|
|
19
|
+
* - `reset` - Resets the list to its initial state
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const [list, actions] = useList<string>(['apple', 'banana']);
|
|
24
|
+
*
|
|
25
|
+
* // Add an item
|
|
26
|
+
* actions.push('cherry');
|
|
27
|
+
*
|
|
28
|
+
* // Insert at index
|
|
29
|
+
* actions.insertAt(1, 'grape');
|
|
30
|
+
*
|
|
31
|
+
* // Update at index
|
|
32
|
+
* actions.updateAt(0, 'orange');
|
|
33
|
+
*
|
|
34
|
+
* // Remove at index
|
|
35
|
+
* actions.removeAt(2);
|
|
36
|
+
*
|
|
37
|
+
* // Replace all
|
|
38
|
+
* actions.setAll(['kiwi', 'mango']);
|
|
39
|
+
*
|
|
40
|
+
* // Reset to initial state
|
|
41
|
+
* actions.reset();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function useList(initialState = []) {
|
|
45
|
+
const [list, setList] = useState(initialState);
|
|
46
|
+
const preservedInitialState = usePreservedReference(initialState);
|
|
47
|
+
const push = usePreservedCallback((value) => {
|
|
48
|
+
setList((prev) => [...prev, value]);
|
|
49
|
+
});
|
|
50
|
+
const insertAt = usePreservedCallback((index, value) => {
|
|
51
|
+
setList((prev) => {
|
|
52
|
+
const next = [...prev];
|
|
53
|
+
next.splice(index, 0, value);
|
|
54
|
+
return next;
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
const updateAt = usePreservedCallback((index, value) => {
|
|
58
|
+
setList((prev) => {
|
|
59
|
+
const next = [...prev];
|
|
60
|
+
next[index] = value;
|
|
61
|
+
return next;
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
const removeAt = usePreservedCallback((index) => {
|
|
65
|
+
setList((prev) => {
|
|
66
|
+
const next = [...prev];
|
|
67
|
+
next.splice(index, 1);
|
|
68
|
+
return next;
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
const setAll = usePreservedCallback((values) => {
|
|
72
|
+
setList(values);
|
|
73
|
+
});
|
|
74
|
+
const reset = usePreservedCallback(() => {
|
|
75
|
+
setList(preservedInitialState);
|
|
76
|
+
});
|
|
77
|
+
return [list, useMemo(() => ({
|
|
78
|
+
push,
|
|
79
|
+
insertAt,
|
|
80
|
+
updateAt,
|
|
81
|
+
removeAt,
|
|
82
|
+
setAll,
|
|
83
|
+
reset
|
|
84
|
+
}), [
|
|
85
|
+
push,
|
|
86
|
+
insertAt,
|
|
87
|
+
updateAt,
|
|
88
|
+
removeAt,
|
|
89
|
+
setAll,
|
|
90
|
+
reset
|
|
91
|
+
])];
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { useList };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
let react = require("react");
|
|
3
|
+
//#region src/hooks/useLoading/useLoading.ts
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* `useLoading` is a React hook that simplifies managing the loading state of a `Promise`.
|
|
7
|
+
* It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
|
|
8
|
+
*
|
|
9
|
+
* @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
|
|
10
|
+
* - loading `boolean` - Represents the current loading state.
|
|
11
|
+
* : The initial value is `false`.
|
|
12
|
+
* : It is set to `true` when an asynchronous task is in progress;
|
|
13
|
+
*
|
|
14
|
+
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
|
|
15
|
+
* : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* function ConfirmButton() {
|
|
19
|
+
* const [loading, startLoading] = useLoading();
|
|
20
|
+
*
|
|
21
|
+
* const handleSubmit = useCallback(async () => {
|
|
22
|
+
* try {
|
|
23
|
+
* const result = await startLoading(postConfirmation());
|
|
24
|
+
* router.push(`/success?id=${result.id}`);
|
|
25
|
+
* } catch (error) {
|
|
26
|
+
* console.error('Error:', error);
|
|
27
|
+
* }
|
|
28
|
+
* }, [startLoading]);
|
|
29
|
+
*
|
|
30
|
+
* return (
|
|
31
|
+
* <button disabled={loading} onClick={handleSubmit}>
|
|
32
|
+
* {loading ? 'Loading...' : 'Confirm'}
|
|
33
|
+
* </button>
|
|
34
|
+
* );
|
|
35
|
+
* }
|
|
36
|
+
*/
|
|
37
|
+
function useLoading() {
|
|
38
|
+
const [loading, setLoading] = (0, react.useState)(false);
|
|
39
|
+
const ref = useIsMountedRef();
|
|
40
|
+
const startTransition = (0, react.useCallback)(async (promise) => {
|
|
41
|
+
try {
|
|
42
|
+
setLoading(true);
|
|
43
|
+
return await promise;
|
|
44
|
+
} finally {
|
|
45
|
+
if (ref.isMounted) setLoading(false);
|
|
46
|
+
}
|
|
47
|
+
}, [ref.isMounted]);
|
|
48
|
+
return (0, react.useMemo)(() => [loading, startTransition], [loading, startTransition]);
|
|
49
|
+
}
|
|
50
|
+
function useIsMountedRef() {
|
|
51
|
+
const ref = (0, react.useRef)({ isMounted: true }).current;
|
|
52
|
+
(0, react.useEffect)(function trackMountedState() {
|
|
53
|
+
ref.isMounted = true;
|
|
54
|
+
return () => {
|
|
55
|
+
ref.isMounted = false;
|
|
56
|
+
};
|
|
57
|
+
}, [ref]);
|
|
58
|
+
return ref;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
exports.useLoading = useLoading;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/hooks/useLoading/useLoading.d.ts
|
|
1
3
|
/**
|
|
2
4
|
* @description
|
|
3
5
|
* `useLoading` is a React hook that simplifies managing the loading state of a `Promise`.
|
|
@@ -32,5 +34,5 @@
|
|
|
32
34
|
* }
|
|
33
35
|
*/
|
|
34
36
|
declare function useLoading(): [boolean, <T>(promise: Promise<T>) => Promise<T>];
|
|
35
|
-
|
|
36
|
-
export { useLoading };
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useLoading };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/hooks/useLoading/useLoading.d.ts
|
|
1
3
|
/**
|
|
2
4
|
* @description
|
|
3
5
|
* `useLoading` is a React hook that simplifies managing the loading state of a `Promise`.
|
|
@@ -32,5 +34,5 @@
|
|
|
32
34
|
* }
|
|
33
35
|
*/
|
|
34
36
|
declare function useLoading(): [boolean, <T>(promise: Promise<T>) => Promise<T>];
|
|
35
|
-
|
|
36
|
-
export { useLoading };
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useLoading };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
//#region src/hooks/useLoading/useLoading.ts
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* `useLoading` is a React hook that simplifies managing the loading state of a `Promise`.
|
|
7
|
+
* It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
|
|
8
|
+
*
|
|
9
|
+
* @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
|
|
10
|
+
* - loading `boolean` - Represents the current loading state.
|
|
11
|
+
* : The initial value is `false`.
|
|
12
|
+
* : It is set to `true` when an asynchronous task is in progress;
|
|
13
|
+
*
|
|
14
|
+
* - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
|
|
15
|
+
* : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* function ConfirmButton() {
|
|
19
|
+
* const [loading, startLoading] = useLoading();
|
|
20
|
+
*
|
|
21
|
+
* const handleSubmit = useCallback(async () => {
|
|
22
|
+
* try {
|
|
23
|
+
* const result = await startLoading(postConfirmation());
|
|
24
|
+
* router.push(`/success?id=${result.id}`);
|
|
25
|
+
* } catch (error) {
|
|
26
|
+
* console.error('Error:', error);
|
|
27
|
+
* }
|
|
28
|
+
* }, [startLoading]);
|
|
29
|
+
*
|
|
30
|
+
* return (
|
|
31
|
+
* <button disabled={loading} onClick={handleSubmit}>
|
|
32
|
+
* {loading ? 'Loading...' : 'Confirm'}
|
|
33
|
+
* </button>
|
|
34
|
+
* );
|
|
35
|
+
* }
|
|
36
|
+
*/
|
|
37
|
+
function useLoading() {
|
|
38
|
+
const [loading, setLoading] = useState(false);
|
|
39
|
+
const ref = useIsMountedRef();
|
|
40
|
+
const startTransition = useCallback(async (promise) => {
|
|
41
|
+
try {
|
|
42
|
+
setLoading(true);
|
|
43
|
+
return await promise;
|
|
44
|
+
} finally {
|
|
45
|
+
if (ref.isMounted) setLoading(false);
|
|
46
|
+
}
|
|
47
|
+
}, [ref.isMounted]);
|
|
48
|
+
return useMemo(() => [loading, startTransition], [loading, startTransition]);
|
|
49
|
+
}
|
|
50
|
+
function useIsMountedRef() {
|
|
51
|
+
const ref = useRef({ isMounted: true }).current;
|
|
52
|
+
useEffect(function trackMountedState() {
|
|
53
|
+
ref.isMounted = true;
|
|
54
|
+
return () => {
|
|
55
|
+
ref.isMounted = false;
|
|
56
|
+
};
|
|
57
|
+
}, [ref]);
|
|
58
|
+
return ref;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { useLoading };
|
|
@@ -1,74 +1,3 @@
|
|
|
1
|
-
import { MouseEvent, TouchEvent } from 'react';
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
delay?: number;
|
|
6
|
-
moveThreshold?: {
|
|
7
|
-
x?: number;
|
|
8
|
-
y?: number;
|
|
9
|
-
};
|
|
10
|
-
onClick?: Handler<E>;
|
|
11
|
-
onLongPressEnd?: Handler<E>;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated This hook is deprecated as it depends on browser-specific APIs (DOM events, window.setTimeout).
|
|
15
|
-
* react-simplikit is now focused on platform-independent, pure state/logic hooks.
|
|
16
|
-
* This hook will be removed in a future major version.
|
|
17
|
-
*
|
|
18
|
-
* @description
|
|
19
|
-
* `useLongPress` is a React hook that detects when an element is pressed and held for a specified duration.
|
|
20
|
-
* It handles both mouse and touch events, making it work consistently across desktop and mobile devices.
|
|
21
|
-
*
|
|
22
|
-
* @template {HTMLElement} E - The HTML element type that will use the long press handlers.
|
|
23
|
-
* @param {(event: React.MouseEvent<E> | React.TouchEvent<E>) => void} onLongPress - The callback function to be executed when a long press is detected.
|
|
24
|
-
* @param {UseLongPressOptions} [options] - Configuration options for the long press behavior.
|
|
25
|
-
* @param {number} [options.delay=500] - The time in milliseconds before triggering the long press. Defaults to 500ms.
|
|
26
|
-
* @param {Object} [options.moveThreshold] - Maximum movement allowed before canceling a long press.
|
|
27
|
-
* @param {number} [options.moveThreshold.x] - Maximum horizontal movement in pixels.
|
|
28
|
-
* @param {number} [options.moveThreshold.y] - Maximum vertical movement in pixels.
|
|
29
|
-
* @param {(event) => void} [options.onClick] - Optional function to execute on a normal click (press and release before delay).
|
|
30
|
-
* @param {(event) => void} [options.onLongPressEnd] - Optional function to execute when a long press ends.
|
|
31
|
-
*
|
|
32
|
-
* @returns {Object} Event handlers to attach to an element.
|
|
33
|
-
* - onMouseDown `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse down events.
|
|
34
|
-
* - onMouseUp `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse up events.
|
|
35
|
-
* - onMouseLeave `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse leave events.
|
|
36
|
-
* - onTouchStart `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch start events.
|
|
37
|
-
* - onTouchEnd `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch end events.
|
|
38
|
-
* - onMouseMove `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for mouse move events. Included if `moveThreshold` is provided.
|
|
39
|
-
* - onTouchMove `(event: MouseEvent<E> | TouchEvent<E>) => void` - Event handler for touch move events. Included if `moveThreshold` is provided.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* import { useLongPress } from 'react-simplikit';
|
|
43
|
-
*
|
|
44
|
-
* function ContextMenu() {
|
|
45
|
-
* const [menuVisible, setMenuVisible] = useState(false);
|
|
46
|
-
*
|
|
47
|
-
* const longPressHandlers = useLongPress(
|
|
48
|
-
* () => setMenuVisible(true),
|
|
49
|
-
* {
|
|
50
|
-
* delay: 400,
|
|
51
|
-
* onClick: () => console.log('Normal click'),
|
|
52
|
-
* onLongPressEnd: () => console.log('Long press completed')
|
|
53
|
-
* }
|
|
54
|
-
* );
|
|
55
|
-
*
|
|
56
|
-
* return (
|
|
57
|
-
* <div>
|
|
58
|
-
* <button {...longPressHandlers}>Press and hold</button>
|
|
59
|
-
* {menuVisible && <div className="context-menu">Context Menu</div>}
|
|
60
|
-
* </div>
|
|
61
|
-
* );
|
|
62
|
-
* }
|
|
63
|
-
*/
|
|
64
|
-
declare function useLongPress<E extends HTMLElement = HTMLElement>(onLongPress: Handler<E>, { delay, moveThreshold, onClick, onLongPressEnd }?: UseLongPressOptions<E>): {
|
|
65
|
-
onTouchMove?: ((event: MouseEvent<E> | TouchEvent<E>) => void) | undefined;
|
|
66
|
-
onMouseMove?: ((event: MouseEvent<E> | TouchEvent<E>) => void) | undefined;
|
|
67
|
-
onMouseDown: (event: MouseEvent<E> | TouchEvent<E>) => void;
|
|
68
|
-
onMouseUp: (event: MouseEvent<E> | TouchEvent<E>) => void;
|
|
69
|
-
onMouseLeave: () => void;
|
|
70
|
-
onTouchStart: (event: MouseEvent<E> | TouchEvent<E>) => void;
|
|
71
|
-
onTouchEnd: (event: MouseEvent<E> | TouchEvent<E>) => void;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export { useLongPress };
|
|
2
|
+
import { useLongPress } from "./useLongPress.cjs";
|
|
3
|
+
export { useLongPress };
|