@siberiacancode/reactuse 0.0.8 → 0.0.10
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/cjs/{_rollupPluginBabelHelpers-Cva0m6Ep.js → _rollupPluginBabelHelpers-BvBejAnn.js} +3 -3
- package/dist/cjs/_rollupPluginBabelHelpers-BvBejAnn.js.map +1 -0
- package/dist/cjs/hooks/index.js +2 -2
- package/dist/cjs/hooks/useBattery/useBattery.js +2 -2
- package/dist/cjs/hooks/useBoolean/useBoolean.js +2 -2
- package/dist/cjs/hooks/useClickOutside/useClickOutside.js +2 -2
- package/dist/cjs/hooks/useClickOutside/useClickOutside.js.map +1 -1
- package/dist/cjs/hooks/useCopyToClipboard/useCopyToClipboard.js +2 -2
- package/dist/cjs/hooks/useCounter/useCounter.js +2 -2
- package/dist/cjs/hooks/useCounter/useCounter.js.map +1 -1
- package/dist/cjs/hooks/useDebouncedValue/useDebouncedValue.js +2 -2
- package/dist/cjs/hooks/useDebouncedValue/useDebouncedValue.js.map +1 -1
- package/dist/cjs/hooks/useDefault/useDefault.js +3 -0
- package/dist/cjs/hooks/useDefault/useDefault.js.map +1 -0
- package/dist/cjs/hooks/useDidUpdate/useDidUpdate.js +3 -0
- package/dist/cjs/hooks/useDidUpdate/useDidUpdate.js.map +1 -0
- package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.js +2 -2
- package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.js.map +1 -1
- package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.js +2 -2
- package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.js.map +1 -1
- package/dist/cjs/hooks/useEvent/useEvent.js +3 -0
- package/dist/cjs/hooks/useEvent/useEvent.js.map +1 -0
- package/dist/cjs/hooks/useEventListener/useEventListener.js +1 -1
- package/dist/cjs/hooks/useEventListener/useEventListener.js.map +1 -1
- package/dist/cjs/hooks/useFavicon/useFavicon.js +3 -0
- package/dist/cjs/hooks/useFavicon/useFavicon.js.map +1 -0
- package/dist/cjs/hooks/useHash/useHash.js +3 -0
- package/dist/cjs/hooks/useHash/useHash.js.map +1 -0
- package/dist/cjs/hooks/useHotkeys/useHotkeys.js +3 -0
- package/dist/cjs/hooks/useHotkeys/useHotkeys.js.map +1 -0
- package/dist/cjs/hooks/useHover/useHover.js +2 -2
- package/dist/cjs/hooks/useHover/useHover.js.map +1 -1
- package/dist/cjs/hooks/useIdle/useIdle.js +3 -0
- package/dist/cjs/hooks/useIdle/useIdle.js.map +1 -0
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.js +3 -0
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.js.map +1 -0
- package/dist/cjs/hooks/useIsFirstRender/useIsFirstRender.js +3 -0
- package/dist/cjs/hooks/useIsFirstRender/useIsFirstRender.js.map +1 -0
- package/dist/cjs/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +1 -1
- package/dist/cjs/hooks/useKeyPress/useKeyPress.js +2 -2
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.js +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.js +2 -2
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.js.map +1 -1
- package/dist/cjs/hooks/useLocalStorage/useLocalStorage.js +2 -2
- package/dist/cjs/hooks/useLocalStorage/useLocalStorage.js.map +1 -1
- package/dist/cjs/hooks/useLogger/useLogger.js +3 -0
- package/dist/cjs/hooks/useLogger/useLogger.js.map +1 -0
- package/dist/cjs/hooks/useMediaQuery/useMediaQuery.js +3 -0
- package/dist/cjs/hooks/useMediaQuery/useMediaQuery.js.map +1 -0
- package/dist/cjs/hooks/useMount/useMount.js +1 -1
- package/dist/cjs/hooks/useMount/useMount.js.map +1 -1
- package/dist/cjs/hooks/useMutationObserver.js +1 -1
- package/dist/cjs/hooks/useNetwork/useNetwork.js +2 -2
- package/dist/cjs/hooks/useNetwork/useNetwork.js.map +1 -1
- package/dist/cjs/hooks/useOnline/useOnline.js +1 -1
- package/dist/cjs/hooks/useOnline/useOnline.js.map +1 -1
- package/dist/cjs/hooks/useOperatingSystem/useOperatingSystem.js +3 -0
- package/dist/cjs/hooks/useOperatingSystem/useOperatingSystem.js.map +1 -0
- package/dist/cjs/hooks/useOrientation/useOrientation.js +2 -2
- package/dist/cjs/hooks/useOrientation/useOrientation.js.map +1 -1
- package/dist/cjs/hooks/usePrevious/usePrevious.js +3 -0
- package/dist/cjs/hooks/usePrevious/usePrevious.js.map +1 -0
- package/dist/cjs/hooks/useQueue/useQueue.js +3 -0
- package/dist/cjs/hooks/useQueue/useQueue.js.map +1 -0
- package/dist/cjs/hooks/useRenderCount/useRenderCount.js +1 -1
- package/dist/cjs/hooks/useRerender/useRerender.js +3 -0
- package/dist/cjs/hooks/useRerender/useRerender.js.map +1 -0
- package/dist/cjs/hooks/useScript/useScript.js +3 -0
- package/dist/cjs/hooks/useScript/useScript.js.map +1 -0
- package/dist/cjs/hooks/useSessionStorage/useSessionStorage.js +2 -2
- package/dist/cjs/hooks/useSessionStorage/useSessionStorage.js.map +1 -1
- package/dist/cjs/hooks/useSet/useSet.js +3 -0
- package/dist/cjs/hooks/useSet/useSet.js.map +1 -0
- package/dist/cjs/hooks/useStep/useStep.js +2 -2
- package/dist/cjs/hooks/useStep/useStep.js.map +1 -1
- package/dist/cjs/hooks/useStorage/useStorage.js +2 -2
- package/dist/cjs/hooks/useStorage/useStorage.js.map +1 -1
- package/dist/cjs/hooks/useTimeout/useTimeout.js +2 -2
- package/dist/cjs/hooks/useToggle/useToggle.js +2 -2
- package/dist/cjs/hooks/useToggle/useToggle.js.map +1 -1
- package/dist/cjs/hooks/useUnmount/useUnmount.js +1 -1
- package/dist/cjs/hooks/useUnmount/useUnmount.js.map +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.js +1 -1
- package/dist/cjs/hooks/useWindowSize/useWindowSize.js +2 -2
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/utils/helpers/debounce.js +1 -1
- package/dist/cjs/utils/helpers/index.js +2 -2
- package/dist/cjs/utils/helpers/isClient.js +1 -1
- package/dist/cjs/utils/helpers/isShallowEqual.js +1 -1
- package/dist/cjs/utils/helpers/throttle.js +3 -0
- package/dist/cjs/utils/helpers/throttle.js.map +1 -0
- package/dist/esm/{_rollupPluginBabelHelpers-8YyPIzj_.js → _rollupPluginBabelHelpers-D5_r4iwW.js} +3 -3
- package/dist/esm/_rollupPluginBabelHelpers-D5_r4iwW.js.map +1 -0
- package/dist/esm/hooks/index.js +2 -2
- package/dist/esm/hooks/useBattery/useBattery.js +2 -2
- package/dist/esm/hooks/useBoolean/useBoolean.js +2 -2
- package/dist/esm/hooks/useClickOutside/useClickOutside.js +2 -2
- package/dist/esm/hooks/useClickOutside/useClickOutside.js.map +1 -1
- package/dist/esm/hooks/useCopyToClipboard/useCopyToClipboard.js +2 -2
- package/dist/esm/hooks/useCounter/useCounter.js +2 -2
- package/dist/esm/hooks/useCounter/useCounter.js.map +1 -1
- package/dist/esm/hooks/useDebouncedValue/useDebouncedValue.js +2 -2
- package/dist/esm/hooks/useDebouncedValue/useDebouncedValue.js.map +1 -1
- package/dist/esm/hooks/useDefault/useDefault.js +3 -0
- package/dist/esm/hooks/useDefault/useDefault.js.map +1 -0
- package/dist/esm/hooks/{useNonInitialEffect/useNonInitialEffect.js → useDidUpdate/useDidUpdate.js} +3 -3
- package/dist/esm/hooks/useDidUpdate/useDidUpdate.js.map +1 -0
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.js +2 -2
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.js.map +1 -1
- package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.js +2 -2
- package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.js.map +1 -1
- package/dist/esm/hooks/useEvent/useEvent.js +3 -0
- package/dist/esm/hooks/useEvent/useEvent.js.map +1 -0
- package/dist/esm/hooks/useEventListener/useEventListener.js +1 -1
- package/dist/esm/hooks/useEventListener/useEventListener.js.map +1 -1
- package/dist/esm/hooks/useFavicon/useFavicon.js +3 -0
- package/dist/esm/hooks/useFavicon/useFavicon.js.map +1 -0
- package/dist/esm/hooks/useHash/useHash.js +3 -0
- package/dist/esm/hooks/useHash/useHash.js.map +1 -0
- package/dist/esm/hooks/useHotkeys/useHotkeys.js +3 -0
- package/dist/esm/hooks/useHotkeys/useHotkeys.js.map +1 -0
- package/dist/esm/hooks/useHover/useHover.js +2 -2
- package/dist/esm/hooks/useHover/useHover.js.map +1 -1
- package/dist/esm/hooks/useIdle/useIdle.js +3 -0
- package/dist/esm/hooks/useIdle/useIdle.js.map +1 -0
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.js +3 -0
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.js.map +1 -0
- package/dist/esm/hooks/useIsFirstRender/useIsFirstRender.js +3 -0
- package/dist/esm/hooks/useIsFirstRender/useIsFirstRender.js.map +1 -0
- package/dist/esm/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +1 -1
- package/dist/esm/hooks/useKeyPress/useKeyPress.js +2 -2
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.js +1 -1
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.js +2 -2
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.js.map +1 -1
- package/dist/esm/hooks/useLocalStorage/useLocalStorage.js +2 -2
- package/dist/esm/hooks/useLocalStorage/useLocalStorage.js.map +1 -1
- package/dist/esm/hooks/useLogger/useLogger.js +3 -0
- package/dist/esm/hooks/useLogger/useLogger.js.map +1 -0
- package/dist/esm/hooks/useMediaQuery/useMediaQuery.js +3 -0
- package/dist/esm/hooks/useMediaQuery/useMediaQuery.js.map +1 -0
- package/dist/esm/hooks/useMount/useMount.js +1 -1
- package/dist/esm/hooks/useMount/useMount.js.map +1 -1
- package/dist/esm/hooks/useMutationObserver.js +1 -1
- package/dist/esm/hooks/useNetwork/useNetwork.js +2 -2
- package/dist/esm/hooks/useNetwork/useNetwork.js.map +1 -1
- package/dist/esm/hooks/useOnline/useOnline.js +1 -1
- package/dist/esm/hooks/useOnline/useOnline.js.map +1 -1
- package/dist/esm/hooks/useOperatingSystem/useOperatingSystem.js +3 -0
- package/dist/esm/hooks/useOperatingSystem/useOperatingSystem.js.map +1 -0
- package/dist/esm/hooks/useOrientation/useOrientation.js +2 -2
- package/dist/esm/hooks/useOrientation/useOrientation.js.map +1 -1
- package/dist/esm/hooks/usePrevious/usePrevious.js +3 -0
- package/dist/esm/hooks/usePrevious/usePrevious.js.map +1 -0
- package/dist/esm/hooks/useQueue/useQueue.js +3 -0
- package/dist/esm/hooks/useQueue/useQueue.js.map +1 -0
- package/dist/esm/hooks/useRenderCount/useRenderCount.js +1 -1
- package/dist/esm/hooks/useRerender/useRerender.js +3 -0
- package/dist/esm/hooks/useRerender/useRerender.js.map +1 -0
- package/dist/esm/hooks/useScript/useScript.js +3 -0
- package/dist/esm/hooks/useScript/useScript.js.map +1 -0
- package/dist/esm/hooks/useSessionStorage/useSessionStorage.js +2 -2
- package/dist/esm/hooks/useSessionStorage/useSessionStorage.js.map +1 -1
- package/dist/esm/hooks/useSet/useSet.js +3 -0
- package/dist/esm/hooks/useSet/useSet.js.map +1 -0
- package/dist/esm/hooks/useStep/useStep.js +2 -2
- package/dist/esm/hooks/useStep/useStep.js.map +1 -1
- package/dist/esm/hooks/useStorage/useStorage.js +2 -2
- package/dist/esm/hooks/useStorage/useStorage.js.map +1 -1
- package/dist/esm/hooks/useTimeout/useTimeout.js +2 -2
- package/dist/esm/hooks/useToggle/useToggle.js +2 -2
- package/dist/esm/hooks/useToggle/useToggle.js.map +1 -1
- package/dist/esm/hooks/useUnmount/useUnmount.js +1 -1
- package/dist/esm/hooks/useUnmount/useUnmount.js.map +1 -1
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.js +1 -1
- package/dist/esm/hooks/useWindowSize/useWindowSize.js +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/utils/helpers/debounce.js +1 -1
- package/dist/esm/utils/helpers/index.js +2 -2
- package/dist/esm/utils/helpers/isClient.js +1 -1
- package/dist/esm/utils/helpers/isShallowEqual.js +1 -1
- package/dist/esm/utils/helpers/throttle.js +3 -0
- package/dist/esm/utils/helpers/throttle.js.map +1 -0
- package/dist/index.d.ts +347 -33
- package/package.json +2 -1
- package/dist/cjs/_rollupPluginBabelHelpers-Cva0m6Ep.js.map +0 -1
- package/dist/cjs/hooks/useNonInitialEffect/useNonInitialEffect.js +0 -3
- package/dist/cjs/hooks/useNonInitialEffect/useNonInitialEffect.js.map +0 -1
- package/dist/esm/_rollupPluginBabelHelpers-8YyPIzj_.js.map +0 -1
- package/dist/esm/hooks/useNonInitialEffect/useNonInitialEffect.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -46,10 +46,10 @@ type UseBooleanReturn = [
|
|
|
46
46
|
declare const useBoolean: (initialValue?: boolean) => UseBooleanReturn;
|
|
47
47
|
|
|
48
48
|
type UseClickOutsideTarget = React.RefObject<Element | null> | (() => Element) | Element;
|
|
49
|
-
type UseClickOutsideReturn<Target extends UseClickOutsideTarget |
|
|
49
|
+
type UseClickOutsideReturn<Target extends UseClickOutsideTarget | UseClickOutsideTarget[]> = React.RefObject<Target>;
|
|
50
50
|
type UseClickOutside = {
|
|
51
|
-
<Target extends UseClickOutsideTarget |
|
|
52
|
-
<Target extends UseClickOutsideTarget |
|
|
51
|
+
<Target extends UseClickOutsideTarget | UseClickOutsideTarget[]>(target: Target, callback: (event: Event) => void): void;
|
|
52
|
+
<Target extends UseClickOutsideTarget | UseClickOutsideTarget[]>(callback: (event: Event) => void, target?: never): UseClickOutsideReturn<Target>;
|
|
53
53
|
};
|
|
54
54
|
declare const useClickOutside: UseClickOutside;
|
|
55
55
|
|
|
@@ -122,25 +122,46 @@ type UseCounter = {
|
|
|
122
122
|
*
|
|
123
123
|
* @example
|
|
124
124
|
* const { count, dec, inc, reset, set } = useCounter(5);
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* const { count, dec, inc, reset, set } = useCounter({ initialValue: 5, min: 0, max: 10 });
|
|
125
128
|
*/
|
|
126
129
|
declare const useCounter: UseCounter;
|
|
127
130
|
|
|
128
131
|
interface UseDebouncedValueOptions {
|
|
129
132
|
maxWait?: number;
|
|
130
133
|
}
|
|
134
|
+
declare const useDebouncedValue: <Value>(value: Value, delay: number, options?: UseDebouncedValueOptions) => readonly [Value, (value: Value) => void];
|
|
135
|
+
|
|
131
136
|
/**
|
|
132
|
-
* @name
|
|
133
|
-
* @description - Hook that
|
|
137
|
+
* @name useDefault
|
|
138
|
+
* @description - Hook that returns the default value
|
|
134
139
|
*
|
|
135
|
-
* @
|
|
136
|
-
* @param {
|
|
140
|
+
* @template Value The type of the value
|
|
141
|
+
* @param {Value} initialValue The initial value
|
|
142
|
+
* @param {Value} defaultValue The default value
|
|
143
|
+
* @returns {[Value, (value: Value) => void]} An array containing the current value and a function to set the value
|
|
137
144
|
*
|
|
138
145
|
* @example
|
|
139
|
-
* const
|
|
146
|
+
* const [value, setValue] = useDefault(initialValue, defaultValue);
|
|
140
147
|
*/
|
|
141
|
-
declare const
|
|
148
|
+
declare const useDefault: <Value>(initialValue: Value | (() => Value), defaultValue: Value) => readonly [Value, React.Dispatch<React.SetStateAction<Value | null | undefined>>];
|
|
142
149
|
|
|
143
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* @name useDidUpdate
|
|
152
|
+
* @description – Hook that behaves like useEffect, but skips the effect on the initial render
|
|
153
|
+
*
|
|
154
|
+
* @param {React.EffectCallback} effect The effect callback
|
|
155
|
+
* @param {React.DependencyList} [deps] The dependencies list for the effect
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* useDidUpdate(() => {
|
|
159
|
+
* console.log('Won't be called when mounted');
|
|
160
|
+
* }, [deps]);
|
|
161
|
+
*/
|
|
162
|
+
declare const useDidUpdate: (effect: React.EffectCallback, deps?: React.DependencyList) => void;
|
|
163
|
+
|
|
164
|
+
/** The use document title options */
|
|
144
165
|
interface UseDocumentTitleOptions {
|
|
145
166
|
/** Restore the previous title on unmount */
|
|
146
167
|
restoreOnUnmount?: boolean;
|
|
@@ -176,6 +197,8 @@ declare function useDocumentTitle(value?: string, options?: UseDocumentTitleOpti
|
|
|
176
197
|
*/
|
|
177
198
|
declare const useDocumentVisibility: () => DocumentVisibilityState;
|
|
178
199
|
|
|
200
|
+
declare const useEvent: <Params extends unknown[], Return>(callback: (...args: Params) => Return) => ((...args: Params) => Return);
|
|
201
|
+
|
|
179
202
|
type UseEventListenerTarget = React.RefObject<Element | null> | (() => Element) | Element | Window | Document;
|
|
180
203
|
type UseEventListenerOptions = boolean | AddEventListenerOptions;
|
|
181
204
|
type UseEventListenerReturn<Target extends UseEventListenerTarget = any> = React.RefObject<Target>;
|
|
@@ -184,15 +207,83 @@ type UseEventListener = {
|
|
|
184
207
|
<Event extends keyof DocumentEventMap = keyof DocumentEventMap>(target: Document, event: Event | Event[], listener: (this: Document, event: DocumentEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
185
208
|
<Target extends UseEventListenerTarget, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(target: Target, event: Event | Event[], listener: (this: Target, event: HTMLElementEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
186
209
|
<Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(event: Event | Event[], listener: (this: Target, event: HTMLElementEventMap[Event]) => void, options?: UseEventListenerOptions, target?: never): UseEventListenerReturn<Target>;
|
|
210
|
+
<Target extends Element, Event extends keyof MediaQueryListEventMap = keyof MediaQueryListEventMap>(event: Event | Event[], listener: (this: Target, event: MediaQueryListEventMap[Event]) => void, options?: UseEventListenerOptions, target?: never): UseEventListenerReturn<Target>;
|
|
187
211
|
};
|
|
212
|
+
declare const useEventListener: UseEventListener;
|
|
213
|
+
|
|
214
|
+
/** The use favicon options */
|
|
215
|
+
interface UseFaviconOptions {
|
|
216
|
+
/** The rel of the favicon */
|
|
217
|
+
rel: string;
|
|
218
|
+
}
|
|
219
|
+
/** The use favicon return type */
|
|
220
|
+
type UseFaviconReturn = [string, React.Dispatch<React.SetStateAction<string>>];
|
|
188
221
|
/**
|
|
189
|
-
* @name
|
|
190
|
-
* @description - Hook that manages
|
|
222
|
+
* @name useFavicon
|
|
223
|
+
* @description - Hook that manages the favicon
|
|
224
|
+
*
|
|
225
|
+
* @param {string} initialFavicon The initial favicon. If not provided, the current favicon will be used
|
|
226
|
+
* @param {string} [options.rel] The rel of the favicon
|
|
227
|
+
* @returns {UseFaviconReturn} An array containing the current favicon and a function to update the favicon
|
|
191
228
|
*
|
|
192
229
|
* @example
|
|
193
|
-
* const {
|
|
230
|
+
* const { href, set } = useFavicon('https://www.google.com/favicon.ico');
|
|
194
231
|
*/
|
|
195
|
-
declare const
|
|
232
|
+
declare const useFavicon: (initialHref?: string, options?: UseFaviconOptions) => {
|
|
233
|
+
readonly href: string | undefined;
|
|
234
|
+
readonly set: (favicon: string) => void;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/** The use hash return type */
|
|
238
|
+
type UseHashReturn = [string, (value: string) => void];
|
|
239
|
+
/**
|
|
240
|
+
* @name useHash
|
|
241
|
+
* @description - Hook that manages the hash value
|
|
242
|
+
*
|
|
243
|
+
* @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* const [hash, setHash] = useHash();
|
|
247
|
+
*/
|
|
248
|
+
declare const useHash: () => UseHashReturn;
|
|
249
|
+
|
|
250
|
+
/** The use keys pressed params */
|
|
251
|
+
interface UseHotkeysOptions {
|
|
252
|
+
/** The target to attach the event listeners to */
|
|
253
|
+
target?: UseEventListenerTarget;
|
|
254
|
+
/** Enable or disable the event listeners */
|
|
255
|
+
enabled?: boolean;
|
|
256
|
+
/** Whether to prevent the default behavior of the event */
|
|
257
|
+
preventDefault?: boolean;
|
|
258
|
+
/** Alias map for hotkeys */
|
|
259
|
+
aliasMap?: Record<string, string>;
|
|
260
|
+
}
|
|
261
|
+
declare const isHotkeyMatch: (hotkey: string, keys: UseHotkeysKey[]) => boolean;
|
|
262
|
+
type UseHotkeysHotkeys = string[] | string;
|
|
263
|
+
type UseHotkeysKey = {
|
|
264
|
+
key: string;
|
|
265
|
+
code: string;
|
|
266
|
+
alias: string;
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* @name useHotkeys
|
|
270
|
+
* @description - Hook that listens for key press events
|
|
271
|
+
*
|
|
272
|
+
* @param {UseHotkeysHotkeys} hotkeys The key or keys to listen for
|
|
273
|
+
* @param {(event: KeyboardEvent) => void} callback The callback function to be called when the hotkey is pressed
|
|
274
|
+
* @param {UseEventListenerTarget} [options.target=window] The target to attach the event listeners to
|
|
275
|
+
* @param {boolean} [options.enabled=true] Enable or disable the event listeners
|
|
276
|
+
* @param {boolean} [options.preventDefault=true] Whether to prevent the default behavior of the event
|
|
277
|
+
* @param {Record<string, string>} [options.aliasMap] Alias map for hotkeys
|
|
278
|
+
* @returns {useKeysPressedReturns} Array of strings with keys that were press
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* useHotkeys('control+a', () => console.log('hotkey pressed'));
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* useHotkeys('ControlLeft+KeyA', () => console.log('hotkey pressed'));
|
|
285
|
+
*/
|
|
286
|
+
declare const useHotkeys: (hotkeys: UseHotkeysHotkeys, callback: (event: KeyboardEvent) => void, options?: UseHotkeysOptions) => void;
|
|
196
287
|
|
|
197
288
|
interface UseHoverOptions {
|
|
198
289
|
onEntry?: () => void;
|
|
@@ -233,6 +324,46 @@ type UseHover = {
|
|
|
233
324
|
*/
|
|
234
325
|
declare const useHover: UseHover;
|
|
235
326
|
|
|
327
|
+
interface UseIdleOptions {
|
|
328
|
+
initialState?: boolean;
|
|
329
|
+
events?: Array<keyof WindowEventMap>;
|
|
330
|
+
}
|
|
331
|
+
interface UseIdleReturn {
|
|
332
|
+
idle: boolean;
|
|
333
|
+
lastActive: number;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* @name useIdle
|
|
337
|
+
* @description - Hook that defines the logic when the user is idle
|
|
338
|
+
*
|
|
339
|
+
* @param {number} [milliseconds=ONE_MINUTE] The idle time in milliseconds
|
|
340
|
+
* @param {boolean} [options.initialState=false] The options for the hook
|
|
341
|
+
* @param {Array<keyof WindowEventMap>} [options.events=IDLE_EVENTS]
|
|
342
|
+
* @returns {UseIdleReturn} An object containing the idle state and the last active time
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* const { idle, lastActive } = useIdle();
|
|
346
|
+
*/
|
|
347
|
+
declare const useIdle: (milliseconds?: number, { initialState, events }?: UseIdleOptions) => UseIdleReturn;
|
|
348
|
+
|
|
349
|
+
type UseIntersectionObserverTarget = React.RefObject<Element | null> | (() => Element) | Element;
|
|
350
|
+
interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, 'root'> {
|
|
351
|
+
immediate?: boolean;
|
|
352
|
+
onChange?: (entry: IntersectionObserverEntry) => void;
|
|
353
|
+
root?: IntersectionObserverInit['root'] | React.RefObject<Element | null>;
|
|
354
|
+
}
|
|
355
|
+
interface UseIntersectionObserverReturn {
|
|
356
|
+
inView: boolean;
|
|
357
|
+
entry?: IntersectionObserverEntry;
|
|
358
|
+
}
|
|
359
|
+
type UseIntersectionObserver = {
|
|
360
|
+
<Target extends UseIntersectionObserverTarget>(target: Target, options?: UseIntersectionObserverOptions): UseIntersectionObserverReturn;
|
|
361
|
+
<Target extends UseIntersectionObserverTarget>(options?: UseIntersectionObserverOptions, target?: never): UseIntersectionObserverReturn & {
|
|
362
|
+
ref: React.RefObject<Target>;
|
|
363
|
+
};
|
|
364
|
+
};
|
|
365
|
+
declare const useIntersectionObserver: UseIntersectionObserver;
|
|
366
|
+
|
|
236
367
|
/**
|
|
237
368
|
* @name useIsomorphicLayoutEffect
|
|
238
369
|
* @description - Hook conditionally selects either `useLayoutEffect` or `useEffect` based on the environment
|
|
@@ -307,17 +438,55 @@ type UseStorageReturn<Value> = [
|
|
|
307
438
|
remove: () => void
|
|
308
439
|
];
|
|
309
440
|
declare const dispatchStorageEvent: (params: Partial<StorageEvent>) => boolean;
|
|
441
|
+
declare const useStorage: <Value>(key: string, params?: UseStorageInitialValue<Value> | UseStorageOptions<Value>) => readonly [Value, (value: Value) => void, () => void];
|
|
442
|
+
|
|
310
443
|
/**
|
|
311
|
-
* @name
|
|
312
|
-
* @description - Hook that manages
|
|
444
|
+
* @name useLocalStorage
|
|
445
|
+
* @description - Hook that manages local storage value
|
|
446
|
+
*
|
|
447
|
+
* @template Value The type of the value
|
|
448
|
+
* @param {string} key The key of the storage
|
|
449
|
+
* @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage
|
|
450
|
+
* @param {UseStorageOptions<Value>} [options] The options of the storage
|
|
313
451
|
*
|
|
314
452
|
* @example
|
|
315
|
-
*
|
|
453
|
+
* const [value, setValue, removeValue] = useLocalStorage('key', 'value');
|
|
316
454
|
*/
|
|
317
|
-
declare const
|
|
455
|
+
declare const useLocalStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) => readonly [Value, (value: Value) => void, () => void];
|
|
318
456
|
|
|
319
|
-
|
|
457
|
+
/**
|
|
458
|
+
* @name useLogger
|
|
459
|
+
* @description - Hook for debugging lifecycle
|
|
460
|
+
*
|
|
461
|
+
* @param {string} name The name or identifier for the logger
|
|
462
|
+
* @param {unknown[]} params Additional arguments to be logged
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* useLogger('Component', [1, 2, 3]);
|
|
466
|
+
*/
|
|
467
|
+
declare const useLogger: (name: string, params: unknown[]) => void;
|
|
320
468
|
|
|
469
|
+
/**
|
|
470
|
+
* @name useMediaQuery
|
|
471
|
+
* @description - Hook that manages a media query
|
|
472
|
+
*
|
|
473
|
+
* @param {string} query The media query string
|
|
474
|
+
* @returns {boolean} A boolean indicating if the media query matches
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* const matches = useMediaQuery('(max-width: 768px)');
|
|
478
|
+
*/
|
|
479
|
+
declare const useMediaQuery: (query: string) => boolean;
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* @name useMount
|
|
483
|
+
* @description - Hook that executes a callback when the component mounts
|
|
484
|
+
*
|
|
485
|
+
* @param {React.EffectCallback} effect The callback to execute
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* useMount(() => console.log('This effect runs on the initial render'));
|
|
489
|
+
*/
|
|
321
490
|
declare const useMount: (effect: React.EffectCallback) => void;
|
|
322
491
|
|
|
323
492
|
type ConnectionType = Connection['type'];
|
|
@@ -352,25 +521,89 @@ declare const getConnection: () => Connection;
|
|
|
352
521
|
declare const useNetwork: () => UseNetworkReturn;
|
|
353
522
|
|
|
354
523
|
/**
|
|
355
|
-
* @name
|
|
356
|
-
* @description
|
|
524
|
+
* @name useOnline
|
|
525
|
+
* @description - Hook that manages if the user is online
|
|
357
526
|
*
|
|
358
|
-
* @
|
|
359
|
-
* @param {React.DependencyList} [deps] The dependencies list for the effect
|
|
527
|
+
* @returns {boolean} A boolean indicating if the user is online
|
|
360
528
|
*
|
|
361
529
|
* @example
|
|
362
|
-
*
|
|
363
|
-
* console.log('this effect doesn't run on the initial render');
|
|
364
|
-
* });
|
|
530
|
+
* const online = useOnline();
|
|
365
531
|
*/
|
|
366
|
-
declare const useNonInitialEffect: (effect: React.EffectCallback, deps?: React.DependencyList) => void;
|
|
367
|
-
|
|
368
532
|
declare const useOnline: () => boolean;
|
|
369
533
|
|
|
370
|
-
|
|
534
|
+
type OperatingSystem = 'undetermined' | 'macos' | 'ios' | 'windows' | 'android' | 'linux';
|
|
535
|
+
declare const getOperatingSystem: () => OperatingSystem;
|
|
536
|
+
/**
|
|
537
|
+
* @name useOperatingSystem
|
|
538
|
+
* @description - Hook that returns the operating system of the current browser
|
|
539
|
+
*
|
|
540
|
+
* @returns {OperatingSystem} The operating system
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
* const operatingSystem = useOperatingSystem();
|
|
544
|
+
*/
|
|
545
|
+
declare const useOperatingSystem: () => OperatingSystem;
|
|
546
|
+
|
|
547
|
+
/** The use orientation return type */
|
|
548
|
+
interface UseOrientationReturn {
|
|
549
|
+
/** The current screen orientation angle */
|
|
371
550
|
angle: number;
|
|
551
|
+
/** The screen orientation type */
|
|
372
552
|
type: OrientationType;
|
|
373
|
-
}
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* @name useOrientation
|
|
556
|
+
* @description - Hook that returns the current screen orientation
|
|
557
|
+
*
|
|
558
|
+
* @returns {UseOrientationReturn} An object containing the current screen orientation
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* const { angle, type } = useOrientation();
|
|
562
|
+
*/
|
|
563
|
+
declare const useOrientation: () => UseOrientationReturn;
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* @name usePrevious
|
|
567
|
+
* @description - Hook that returns the previous value
|
|
568
|
+
*
|
|
569
|
+
* @template Value The type of the value
|
|
570
|
+
* @param {Value} value The value to get the previous value
|
|
571
|
+
* @returns {Value} The previous value
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* const prevValue = usePrevious(value);
|
|
575
|
+
*/
|
|
576
|
+
declare const usePrevious: <Value>(value: Value) => Value | undefined;
|
|
577
|
+
|
|
578
|
+
/** The use queue return type */
|
|
579
|
+
interface UseQueueReturn<Value> {
|
|
580
|
+
/** The current queue */
|
|
581
|
+
queue: Value[];
|
|
582
|
+
/** Add an element to the queue */
|
|
583
|
+
add: (element: Value) => void;
|
|
584
|
+
/** Remove an element from the queue */
|
|
585
|
+
remove: () => Value;
|
|
586
|
+
/** Clear the queue */
|
|
587
|
+
clear: () => void;
|
|
588
|
+
/** Get the first element of the queue */
|
|
589
|
+
first: Value;
|
|
590
|
+
/** Get the last element of the queue */
|
|
591
|
+
last: Value;
|
|
592
|
+
/** Get the size of the queue */
|
|
593
|
+
size: number;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* @name useQueue
|
|
597
|
+
* @description - Hook that manages a queue
|
|
598
|
+
*
|
|
599
|
+
* @template Value The type of the value
|
|
600
|
+
* @param {Value[]} [initialValue=[]] The initial value of the queue
|
|
601
|
+
* @returns {UseQueueReturn} An object containing the current queue and functions to interact with the queue
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* const { queue, add, remove, clear, first, last, size } = useQueue([1, 2, 3]);
|
|
605
|
+
*/
|
|
606
|
+
declare const useQueue: <Value>(initialValue?: Value[]) => UseQueueReturn<Value>;
|
|
374
607
|
|
|
375
608
|
/**
|
|
376
609
|
* @name useRenderCount
|
|
@@ -383,7 +616,73 @@ declare const useOrientation: () => {
|
|
|
383
616
|
*/
|
|
384
617
|
declare const useRenderCount: () => number;
|
|
385
618
|
|
|
386
|
-
|
|
619
|
+
/** The use rerender return type */
|
|
620
|
+
interface UseRerenderReturns {
|
|
621
|
+
/** The id of the rerender */
|
|
622
|
+
id: string;
|
|
623
|
+
/** Function to rerender the component */
|
|
624
|
+
update: () => void;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* @name useRerender
|
|
628
|
+
* @description - Hook that defines the logic to force rerender a component
|
|
629
|
+
*
|
|
630
|
+
* @returns {UseRerenderReturns} An object containing the id and update function
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* const { id, update } = useRerender();
|
|
634
|
+
*/
|
|
635
|
+
declare const useRerender: () => UseRerenderReturns;
|
|
636
|
+
|
|
637
|
+
/** The use script status */
|
|
638
|
+
type UseScriptStatus = 'loading' | 'ready' | 'error' | 'unknown';
|
|
639
|
+
declare const SCRIPT_STATUS_ATTRIBUTE_NAME = "script-status";
|
|
640
|
+
/** The use script options extends from attributes script tag */
|
|
641
|
+
interface UseScriptOptions extends React.ComponentProps<'script'> {
|
|
642
|
+
/** Whether to remove the script on unmount */
|
|
643
|
+
removeOnUnmount?: boolean;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* @name useScript
|
|
647
|
+
* @description - Hook that manages a script with onLoad, onError, and removeOnUnmount functionalities
|
|
648
|
+
*
|
|
649
|
+
* @param {string} src The source of the script
|
|
650
|
+
* @param {UseScriptOptions} [options] The options of the script extends from attributes script tag
|
|
651
|
+
* @param {boolean} [options.removeOnUnmount=true] Whether to remove the script on unmount
|
|
652
|
+
* @param {boolean} [options.async=true] Whether to load the script asynchronously
|
|
653
|
+
* @returns {UseScriptStatus} The status of the script
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* const status = useScript('https://example.com/script.js');
|
|
657
|
+
*/
|
|
658
|
+
declare const useScript: (src: string, options?: UseScriptOptions) => UseScriptStatus;
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* @name useSessionStorage
|
|
662
|
+
* @description - Hook that manages session storage value
|
|
663
|
+
*
|
|
664
|
+
* @template Value The type of the value
|
|
665
|
+
* @param {string} key The key of the storage
|
|
666
|
+
* @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage
|
|
667
|
+
* @param {UseStorageOptions<Value>} [options] The options of the storage
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* const [value, setValue, removeValue] = useSessionStorage('key', 'value');
|
|
671
|
+
*/
|
|
672
|
+
declare const useSessionStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) => readonly [Value, (value: Value) => void, () => void];
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* @name useSet
|
|
676
|
+
* @description - Hook that manages a set structure
|
|
677
|
+
*
|
|
678
|
+
* @template Value The type of the value
|
|
679
|
+
* @param {Value[]} values The initial array of the set
|
|
680
|
+
* @returns {Set<Value>} A set structure
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* const set = useSet([1, 2, 3]);
|
|
684
|
+
*/
|
|
685
|
+
declare const useSet: <Value>(values: Value[]) => Set<Value>;
|
|
387
686
|
|
|
388
687
|
/** The use step params */
|
|
389
688
|
interface UseStepParams {
|
|
@@ -426,6 +725,7 @@ interface UseStepReturn {
|
|
|
426
725
|
*
|
|
427
726
|
* @example
|
|
428
727
|
* const step = useStep(5);
|
|
728
|
+
*
|
|
429
729
|
* @example
|
|
430
730
|
* const stepper = useStep({ initial: 2, max: 5 });
|
|
431
731
|
*/
|
|
@@ -451,7 +751,21 @@ interface UseTimeoutReturn {
|
|
|
451
751
|
*/
|
|
452
752
|
declare function useTimeout(callback: () => void, delay: number): UseTimeoutReturn;
|
|
453
753
|
|
|
754
|
+
/** The use toggle return type */
|
|
454
755
|
type UseToggleReturn<Value> = readonly [Value, (value?: Value) => void];
|
|
756
|
+
/**
|
|
757
|
+
* @name useToggle
|
|
758
|
+
* @description - Hook that create toggle
|
|
759
|
+
*
|
|
760
|
+
* @template Value The type of the value
|
|
761
|
+
* @param {Value[]} [values=[false, true]] The values to toggle
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* const [on, toggle] = useToggle();
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* const [value, toggle] = useToggle(['light', 'dark'] as const);
|
|
768
|
+
*/
|
|
455
769
|
declare const useToggle: <Value = boolean>(values?: readonly Value[]) => readonly [Value, (value?: Value) => void];
|
|
456
770
|
|
|
457
771
|
/**
|
|
@@ -462,7 +776,7 @@ declare const useToggle: <Value = boolean>(values?: readonly Value[]) => readonl
|
|
|
462
776
|
* @returns {void}
|
|
463
777
|
*
|
|
464
778
|
* @example
|
|
465
|
-
* useUnmount(() => console.log('
|
|
779
|
+
* useUnmount(() => console.log('This effect runs on component unmount'));
|
|
466
780
|
*/
|
|
467
781
|
declare const useUnmount: (callback: () => void) => void;
|
|
468
782
|
|
|
@@ -511,4 +825,4 @@ declare const useWindowSize: (params?: UseWindowSizeParams) => {
|
|
|
511
825
|
height: number;
|
|
512
826
|
};
|
|
513
827
|
|
|
514
|
-
export { type ConnectionEffectiveType, type ConnectionType, type UseClickOutside, type UseClickOutsideReturn, type UseCounter, type UseCounterOptions, type UseCounterParams, type UseCounterReturn, type UseDocumentTitleOptions, type UseDocumentTitleReturn, type UseEventListener, type UseEventListenerOptions, type UseEventListenerReturn, type UseEventListenerTarget, type UseHover, type UseHoverOptions, type UseHoverReturn, type UseHoverTarget, type UseKeyPressEvent, type UseKeyPressEventKey, type UseKeyPressKey, type UseKeyPressOptions, type UseNetworkReturn, type UseStorageInitialValue, type UseStorageOptions, type UseStorageReturn, type UseToggleReturn, type UseWindowSizeReturn, dispatchStorageEvent, getConnection, legacyCopyToClipboard, useBattery, useBoolean, useClickOutside, useCopyToClipboard, useCounter, useDebouncedValue, useDocumentTitle, useDocumentVisibility, useEventListener, useHover, useIsomorphicLayoutEffect, useKeyPress, useKeyPressEvent, useKeysPressed, useLocalStorage, useMount, useNetwork,
|
|
828
|
+
export { type ConnectionEffectiveType, type ConnectionType, type OperatingSystem, SCRIPT_STATUS_ATTRIBUTE_NAME, type UseClickOutside, type UseClickOutsideReturn, type UseCounter, type UseCounterOptions, type UseCounterParams, type UseCounterReturn, type UseDocumentTitleOptions, type UseDocumentTitleReturn, type UseEventListener, type UseEventListenerOptions, type UseEventListenerReturn, type UseEventListenerTarget, type UseFaviconOptions, type UseFaviconReturn, type UseHover, type UseHoverOptions, type UseHoverReturn, type UseHoverTarget, type UseIdleReturn, type UseIntersectionObserver, type UseIntersectionObserverOptions, type UseIntersectionObserverReturn, type UseIntersectionObserverTarget, type UseKeyPressEvent, type UseKeyPressEventKey, type UseKeyPressKey, type UseKeyPressOptions, type UseNetworkReturn, type UseOrientationReturn, type UseQueueReturn, type UseScriptOptions, type UseScriptStatus, type UseStorageInitialValue, type UseStorageOptions, type UseStorageReturn, type UseToggleReturn, type UseWindowSizeReturn, dispatchStorageEvent, getConnection, getOperatingSystem, isHotkeyMatch, legacyCopyToClipboard, useBattery, useBoolean, useClickOutside, useCopyToClipboard, useCounter, useDebouncedValue, useDefault, useDidUpdate, useDocumentTitle, useDocumentVisibility, useEvent, useEventListener, useFavicon, useHash, useHotkeys, useHover, useIdle, useIntersectionObserver, useIsomorphicLayoutEffect, useKeyPress, useKeyPressEvent, useKeysPressed, useLocalStorage, useLogger, useMediaQuery, useMount, useNetwork, useOnline, useOperatingSystem, useOrientation, usePrevious, useQueue, useRenderCount, useRerender, useScript, useSessionStorage, useSet, useStep, useStorage, useTimeout, useToggle, useUnmount, useWindowEvent, useWindowSize };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siberiacancode/reactuse",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Ultimate tool",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"module": "dist/esm/index.js",
|
|
33
33
|
"types": "dist/index.d.ts",
|
|
34
34
|
"scripts": {
|
|
35
|
+
"prepublish": "yarn type && yarn unit-test run && yarn build",
|
|
35
36
|
"build": "shx rm -rf dist && rollup -c --bundleConfigAsCjs",
|
|
36
37
|
"lint": "eslint . --ext ts --ext tsx --no-error-on-unmatched-pattern --fix",
|
|
37
38
|
"format": "prettier --write **/*.{ts,jsm,md}",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_rollupPluginBabelHelpers-Cva0m6Ep.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/* @license @siberiacancode/reactuse v0.0.5 */
|
|
2
|
-
"use strict";var e=require("react"),r=require("../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js");require("../../utils/helpers/isClient.js");exports.useNonInitialEffect=function(t,u){var i=e.useRef(!0);r.useIsomorphicLayoutEffect((function(){if(!i.current){var e=t();return e&&"function"==typeof e?e:void 0}i.current=!1}),u)};
|
|
3
|
-
//# sourceMappingURL=useNonInitialEffect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useNonInitialEffect.js","sources":["../../../../src/hooks/useNonInitialEffect/useNonInitialEffect.ts"],"sourcesContent":["import React from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\n\n/**\n * @name useNonInitialEffect\n * @description – Hook that behaves like useEffect, but skips the effect on the initial render\n *\n * @param {React.EffectCallback} effect The effect callback\n * @param {React.DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useNonInitialEffect(() => {\n * console.log('this effect doesn't run on the initial render');\n * });\n */\nexport const useNonInitialEffect = (effect: React.EffectCallback, deps?: React.DependencyList) => {\n const initialRender = React.useRef(true);\n\n useIsomorphicLayoutEffect(() => {\n if (initialRender.current) {\n initialRender.current = false;\n return;\n }\n\n const effectReturns = effect();\n if (effectReturns && typeof effectReturns === 'function') {\n return effectReturns;\n }\n }, deps);\n};\n"],"names":["effect","deps","initialRender","React","useRef","useIsomorphicLayoutEffect","current","effectReturns"],"mappings":";kLAgBmC,SAACA,EAA8BC,GAChE,IAAMC,EAAgBC,EAAMC,QAAO,GAEnCC,EAAAA,2BAA0B,WACxB,IAAIH,EAAcI,QAAlB,CAKA,IAAMC,EAAgBP,IACtB,OAAIO,GAA0C,mBAAlBA,EACnBA,OADT,CAHA,CAFEL,EAAcI,SAAU,CAQ3B,GAAEL,EACL"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_rollupPluginBabelHelpers-8YyPIzj_.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useNonInitialEffect.js","sources":["../../../../src/hooks/useNonInitialEffect/useNonInitialEffect.ts"],"sourcesContent":["import React from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\n\n/**\n * @name useNonInitialEffect\n * @description – Hook that behaves like useEffect, but skips the effect on the initial render\n *\n * @param {React.EffectCallback} effect The effect callback\n * @param {React.DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useNonInitialEffect(() => {\n * console.log('this effect doesn't run on the initial render');\n * });\n */\nexport const useNonInitialEffect = (effect: React.EffectCallback, deps?: React.DependencyList) => {\n const initialRender = React.useRef(true);\n\n useIsomorphicLayoutEffect(() => {\n if (initialRender.current) {\n initialRender.current = false;\n return;\n }\n\n const effectReturns = effect();\n if (effectReturns && typeof effectReturns === 'function') {\n return effectReturns;\n }\n }, deps);\n};\n"],"names":["useNonInitialEffect","effect","deps","initialRender","React","useRef","useIsomorphicLayoutEffect","current","effectReturns"],"mappings":";mKAgBO,IAAMA,EAAsB,SAACC,EAA8BC,GAChE,IAAMC,EAAgBC,EAAMC,QAAO,GAEnCC,GAA0B,WACxB,IAAIH,EAAcI,QAAlB,CAKA,IAAMC,EAAgBP,IACtB,OAAIO,GAA0C,mBAAlBA,EACnBA,OADT,CAHA,CAFEL,EAAcI,SAAU,CAQ3B,GAAEL,EACL"}
|