@siberiacancode/reactuse 0.0.7 → 0.0.9
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-Db0KR1gW.js} +2 -2
- package/dist/cjs/_rollupPluginBabelHelpers-Db0KR1gW.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 +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/useDocumentVisibility/useDocumentVisibility.js +1 -1
- 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/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/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/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/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-Cg3Jntln.js} +2 -2
- package/dist/esm/_rollupPluginBabelHelpers-Cg3Jntln.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 +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/useDocumentVisibility/useDocumentVisibility.js +1 -1
- 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/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/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/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/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 +252 -29
- package/package.json +1 -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
|
@@ -122,23 +122,44 @@ 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>>];
|
|
149
|
+
|
|
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;
|
|
142
163
|
|
|
143
164
|
/** The use document title options type */
|
|
144
165
|
interface UseDocumentTitleOptions {
|
|
@@ -184,15 +205,45 @@ type UseEventListener = {
|
|
|
184
205
|
<Event extends keyof DocumentEventMap = keyof DocumentEventMap>(target: Document, event: Event | Event[], listener: (this: Document, event: DocumentEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
185
206
|
<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
207
|
<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>;
|
|
208
|
+
<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
209
|
};
|
|
210
|
+
declare const useEventListener: UseEventListener;
|
|
211
|
+
|
|
212
|
+
/** The use favicon options */
|
|
213
|
+
interface UseFaviconOptions {
|
|
214
|
+
/** The rel of the favicon */
|
|
215
|
+
rel: string;
|
|
216
|
+
}
|
|
217
|
+
/** The use favicon return type */
|
|
218
|
+
type UseFaviconReturn = [string, React.Dispatch<React.SetStateAction<string>>];
|
|
188
219
|
/**
|
|
189
|
-
* @name
|
|
190
|
-
* @description - Hook that manages
|
|
220
|
+
* @name useFavicon
|
|
221
|
+
* @description - Hook that manages the favicon
|
|
222
|
+
*
|
|
223
|
+
* @param {string} initialFavicon The initial favicon. If not provided, the current favicon will be used
|
|
224
|
+
* @param {string} [options.rel] The rel of the favicon
|
|
225
|
+
* @returns {UseFaviconReturn} An array containing the current favicon and a function to update the favicon
|
|
191
226
|
*
|
|
192
227
|
* @example
|
|
193
|
-
* const {
|
|
228
|
+
* const { href, set } = useFavicon('https://www.google.com/favicon.ico');
|
|
194
229
|
*/
|
|
195
|
-
declare const
|
|
230
|
+
declare const useFavicon: (initialHref?: string, options?: UseFaviconOptions) => {
|
|
231
|
+
readonly href: string | undefined;
|
|
232
|
+
readonly set: (favicon: string) => void;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/** The use hash return type */
|
|
236
|
+
type UseHashReturn = [string, (value: string) => void];
|
|
237
|
+
/**
|
|
238
|
+
* @name useHash
|
|
239
|
+
* @description - Hook that manages the hash value
|
|
240
|
+
*
|
|
241
|
+
* @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* const [hash, setHash] = useHash();
|
|
245
|
+
*/
|
|
246
|
+
declare const useHash: () => UseHashReturn;
|
|
196
247
|
|
|
197
248
|
interface UseHoverOptions {
|
|
198
249
|
onEntry?: () => void;
|
|
@@ -233,6 +284,28 @@ type UseHover = {
|
|
|
233
284
|
*/
|
|
234
285
|
declare const useHover: UseHover;
|
|
235
286
|
|
|
287
|
+
interface UseIdleOptions {
|
|
288
|
+
initialState?: boolean;
|
|
289
|
+
events?: Array<keyof WindowEventMap>;
|
|
290
|
+
}
|
|
291
|
+
interface UseIdleReturn {
|
|
292
|
+
idle: boolean;
|
|
293
|
+
lastActive: number;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* @name useIdle
|
|
297
|
+
* @description - Hook that defines the logic when the user is idle
|
|
298
|
+
*
|
|
299
|
+
* @param {number} [milliseconds=ONE_MINUTE] The idle time in milliseconds
|
|
300
|
+
* @param {boolean} [options.initialState=false] The options for the hook
|
|
301
|
+
* @param {Array<keyof WindowEventMap>} [options.events=IDLE_EVENTS]
|
|
302
|
+
* @returns {UseIdleReturn} An object containing the idle state and the last active time
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* const { idle, lastActive } = useIdle();
|
|
306
|
+
*/
|
|
307
|
+
declare const useIdle: (milliseconds?: number, { initialState, events }?: UseIdleOptions) => UseIdleReturn;
|
|
308
|
+
|
|
236
309
|
/**
|
|
237
310
|
* @name useIsomorphicLayoutEffect
|
|
238
311
|
* @description - Hook conditionally selects either `useLayoutEffect` or `useEffect` based on the environment
|
|
@@ -307,17 +380,55 @@ type UseStorageReturn<Value> = [
|
|
|
307
380
|
remove: () => void
|
|
308
381
|
];
|
|
309
382
|
declare const dispatchStorageEvent: (params: Partial<StorageEvent>) => boolean;
|
|
383
|
+
declare const useStorage: <Value>(key: string, params?: UseStorageInitialValue<Value> | UseStorageOptions<Value>) => readonly [Value, (value: Value) => void, () => void];
|
|
384
|
+
|
|
310
385
|
/**
|
|
311
|
-
* @name
|
|
312
|
-
* @description - Hook that manages
|
|
386
|
+
* @name useLocalStorage
|
|
387
|
+
* @description - Hook that manages local storage value
|
|
388
|
+
*
|
|
389
|
+
* @template Value The type of the value
|
|
390
|
+
* @param {string} key The key of the storage
|
|
391
|
+
* @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage
|
|
392
|
+
* @param {UseStorageOptions<Value>} [options] The options of the storage
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* const [value, setValue, removeValue] = useLocalStorage('key', 'value');
|
|
396
|
+
*/
|
|
397
|
+
declare const useLocalStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) => readonly [Value, (value: Value) => void, () => void];
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* @name useLogger
|
|
401
|
+
* @description - Hook for debugging lifecycle
|
|
402
|
+
*
|
|
403
|
+
* @param {string} name The name or identifier for the logger
|
|
404
|
+
* @param {unknown[]} params Additional arguments to be logged
|
|
313
405
|
*
|
|
314
406
|
* @example
|
|
315
|
-
*
|
|
407
|
+
* useLogger('Component', [1, 2, 3]);
|
|
316
408
|
*/
|
|
317
|
-
declare const
|
|
409
|
+
declare const useLogger: (name: string, params: unknown[]) => void;
|
|
318
410
|
|
|
319
|
-
|
|
411
|
+
/**
|
|
412
|
+
* @name useMediaQuery
|
|
413
|
+
* @description - Hook that manages a media query
|
|
414
|
+
*
|
|
415
|
+
* @param {string} query The media query string
|
|
416
|
+
* @returns {boolean} A boolean indicating if the media query matches
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* const matches = useMediaQuery('(max-width: 768px)');
|
|
420
|
+
*/
|
|
421
|
+
declare const useMediaQuery: (query: string) => boolean;
|
|
320
422
|
|
|
423
|
+
/**
|
|
424
|
+
* @name useMount
|
|
425
|
+
* @description - Hook that executes a callback when the component mounts
|
|
426
|
+
*
|
|
427
|
+
* @param {React.EffectCallback} effect The callback to execute
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* useMount(() => console.log('This effect runs on the initial render'));
|
|
431
|
+
*/
|
|
321
432
|
declare const useMount: (effect: React.EffectCallback) => void;
|
|
322
433
|
|
|
323
434
|
type ConnectionType = Connection['type'];
|
|
@@ -352,25 +463,59 @@ declare const getConnection: () => Connection;
|
|
|
352
463
|
declare const useNetwork: () => UseNetworkReturn;
|
|
353
464
|
|
|
354
465
|
/**
|
|
355
|
-
* @name
|
|
356
|
-
* @description
|
|
466
|
+
* @name useOnline
|
|
467
|
+
* @description - Hook that manages if the user is online
|
|
357
468
|
*
|
|
358
|
-
* @
|
|
359
|
-
* @param {React.DependencyList} [deps] The dependencies list for the effect
|
|
469
|
+
* @returns {boolean} A boolean indicating if the user is online
|
|
360
470
|
*
|
|
361
471
|
* @example
|
|
362
|
-
*
|
|
363
|
-
* console.log('this effect doesn't run on the initial render');
|
|
364
|
-
* });
|
|
472
|
+
* const online = useOnline();
|
|
365
473
|
*/
|
|
366
|
-
declare const useNonInitialEffect: (effect: React.EffectCallback, deps?: React.DependencyList) => void;
|
|
367
|
-
|
|
368
474
|
declare const useOnline: () => boolean;
|
|
369
475
|
|
|
370
|
-
|
|
476
|
+
type OperatingSystem = 'undetermined' | 'macos' | 'ios' | 'windows' | 'android' | 'linux';
|
|
477
|
+
declare const getOperatingSystem: () => OperatingSystem;
|
|
478
|
+
/**
|
|
479
|
+
* @name useOperatingSystem
|
|
480
|
+
* @description - Hook that returns the operating system of the current browser
|
|
481
|
+
*
|
|
482
|
+
* @returns {OperatingSystem} The operating system
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* const operatingSystem = useOperatingSystem();
|
|
486
|
+
*/
|
|
487
|
+
declare const useOperatingSystem: () => OperatingSystem;
|
|
488
|
+
|
|
489
|
+
/** The use orientation return type */
|
|
490
|
+
interface UseOrientationReturn {
|
|
491
|
+
/** The current screen orientation angle */
|
|
371
492
|
angle: number;
|
|
493
|
+
/** The screen orientation type */
|
|
372
494
|
type: OrientationType;
|
|
373
|
-
}
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* @name useOrientation
|
|
498
|
+
* @description - Hook that returns the current screen orientation
|
|
499
|
+
*
|
|
500
|
+
* @returns {UseOrientationReturn} An object containing the current screen orientation
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* const { angle, type } = useOrientation();
|
|
504
|
+
*/
|
|
505
|
+
declare const useOrientation: () => UseOrientationReturn;
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* @name usePrevious
|
|
509
|
+
* @description - Hook that returns the previous value
|
|
510
|
+
*
|
|
511
|
+
* @template Value The type of the value
|
|
512
|
+
* @param {Value} value The value to get the previous value
|
|
513
|
+
* @returns {Value} The previous value
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* const prevValue = usePrevious(value);
|
|
517
|
+
*/
|
|
518
|
+
declare const usePrevious: <Value>(value: Value) => Value | undefined;
|
|
374
519
|
|
|
375
520
|
/**
|
|
376
521
|
* @name useRenderCount
|
|
@@ -383,7 +528,70 @@ declare const useOrientation: () => {
|
|
|
383
528
|
*/
|
|
384
529
|
declare const useRenderCount: () => number;
|
|
385
530
|
|
|
386
|
-
|
|
531
|
+
/** The use rerender return type */
|
|
532
|
+
interface UseRerenderReturns {
|
|
533
|
+
/** The id of the rerender */
|
|
534
|
+
id: string;
|
|
535
|
+
/** Function to rerender the component */
|
|
536
|
+
update: () => void;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* @name useRerender
|
|
540
|
+
* @description - Hook that defines the logic to force rerender a component
|
|
541
|
+
*
|
|
542
|
+
* @returns {UseRerenderReturns} An object containing the id and update function
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* const { id, update } = useRerender();
|
|
546
|
+
*/
|
|
547
|
+
declare const useRerender: () => UseRerenderReturns;
|
|
548
|
+
|
|
549
|
+
type UseScriptStatus = 'loading' | 'ready' | 'error' | 'unknown';
|
|
550
|
+
declare const SCRIPT_STATUS_ATTRIBUTE_NAME = "script-status";
|
|
551
|
+
interface UseScriptOptions extends React.ComponentProps<'script'> {
|
|
552
|
+
removeOnUnmount?: boolean;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* @name useScript
|
|
556
|
+
* @description - Hook that manages a script with onLoad, onError, and removeOnUnmount functionalities
|
|
557
|
+
*
|
|
558
|
+
* @param {string} src The source of the script
|
|
559
|
+
* @param {UseScriptOptions} [options] The options of the script extends from attributes script tag
|
|
560
|
+
* @param {boolean} [options.removeOnUnmount=true] Whether to remove the script on unmount
|
|
561
|
+
* @param {boolean} [options.async=true] Whether to load the script asynchronously
|
|
562
|
+
* @returns {UseScriptStatus} The status of the script
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* const status = useScript('https://example.com/script.js');
|
|
566
|
+
*/
|
|
567
|
+
declare const useScript: (src: string, options?: UseScriptOptions) => UseScriptStatus;
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* @name useSessionStorage
|
|
571
|
+
* @description - Hook that manages session storage value
|
|
572
|
+
*
|
|
573
|
+
* @template Value The type of the value
|
|
574
|
+
* @param {string} key The key of the storage
|
|
575
|
+
* @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage
|
|
576
|
+
* @param {UseStorageOptions<Value>} [options] The options of the storage
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
579
|
+
* const [value, setValue, removeValue] = useSessionStorage('key', 'value');
|
|
580
|
+
*/
|
|
581
|
+
declare const useSessionStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) => readonly [Value, (value: Value) => void, () => void];
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* @name useSet
|
|
585
|
+
* @description - Hook that manages a set structure
|
|
586
|
+
*
|
|
587
|
+
* @template Value The type of the value
|
|
588
|
+
* @param {Value[]} values The initial array of the set
|
|
589
|
+
* @returns {Set<Value>} A set structure
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* const set = useSet([1, 2, 3]);
|
|
593
|
+
*/
|
|
594
|
+
declare const useSet: <Value>(values: Value[]) => Set<Value>;
|
|
387
595
|
|
|
388
596
|
/** The use step params */
|
|
389
597
|
interface UseStepParams {
|
|
@@ -426,6 +634,7 @@ interface UseStepReturn {
|
|
|
426
634
|
*
|
|
427
635
|
* @example
|
|
428
636
|
* const step = useStep(5);
|
|
637
|
+
*
|
|
429
638
|
* @example
|
|
430
639
|
* const stepper = useStep({ initial: 2, max: 5 });
|
|
431
640
|
*/
|
|
@@ -451,7 +660,21 @@ interface UseTimeoutReturn {
|
|
|
451
660
|
*/
|
|
452
661
|
declare function useTimeout(callback: () => void, delay: number): UseTimeoutReturn;
|
|
453
662
|
|
|
663
|
+
/** The use toggle return type */
|
|
454
664
|
type UseToggleReturn<Value> = readonly [Value, (value?: Value) => void];
|
|
665
|
+
/**
|
|
666
|
+
* @name useToggle
|
|
667
|
+
* @description - Hook that create toggle
|
|
668
|
+
*
|
|
669
|
+
* @template Value The type of the value
|
|
670
|
+
* @param {Value[]} [values=[false, true]] The values to toggle
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
673
|
+
* const [on, toggle] = useToggle();
|
|
674
|
+
*
|
|
675
|
+
* @example
|
|
676
|
+
* const [value, toggle] = useToggle(['light', 'dark'] as const);
|
|
677
|
+
*/
|
|
455
678
|
declare const useToggle: <Value = boolean>(values?: readonly Value[]) => readonly [Value, (value?: Value) => void];
|
|
456
679
|
|
|
457
680
|
/**
|
|
@@ -462,7 +685,7 @@ declare const useToggle: <Value = boolean>(values?: readonly Value[]) => readonl
|
|
|
462
685
|
* @returns {void}
|
|
463
686
|
*
|
|
464
687
|
* @example
|
|
465
|
-
* useUnmount(() => console.log('
|
|
688
|
+
* useUnmount(() => console.log('This effect runs on component unmount'));
|
|
466
689
|
*/
|
|
467
690
|
declare const useUnmount: (callback: () => void) => void;
|
|
468
691
|
|
|
@@ -511,4 +734,4 @@ declare const useWindowSize: (params?: UseWindowSizeParams) => {
|
|
|
511
734
|
height: number;
|
|
512
735
|
};
|
|
513
736
|
|
|
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,
|
|
737
|
+
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 UseKeyPressEvent, type UseKeyPressEventKey, type UseKeyPressKey, type UseKeyPressOptions, type UseNetworkReturn, type UseOrientationReturn, type UseScriptOptions, type UseScriptStatus, type UseStorageInitialValue, type UseStorageOptions, type UseStorageReturn, type UseToggleReturn, type UseWindowSizeReturn, dispatchStorageEvent, getConnection, getOperatingSystem, legacyCopyToClipboard, useBattery, useBoolean, useClickOutside, useCopyToClipboard, useCounter, useDebouncedValue, useDefault, useDidUpdate, useDocumentTitle, useDocumentVisibility, useEventListener, useFavicon, useHash, useHover, useIdle, useIsomorphicLayoutEffect, useKeyPress, useKeyPressEvent, useKeysPressed, useLocalStorage, useLogger, useMediaQuery, useMount, useNetwork, useOnline, useOperatingSystem, useOrientation, usePrevious, useRenderCount, useRerender, useScript, useSessionStorage, useSet, useStep, useStorage, useTimeout, useToggle, useUnmount, useWindowEvent, useWindowSize };
|
package/package.json
CHANGED
|
@@ -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"}
|