@siberiacancode/reactuse 0.0.8 → 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.
Files changed (165) hide show
  1. package/dist/cjs/{_rollupPluginBabelHelpers-Cva0m6Ep.js → _rollupPluginBabelHelpers-Db0KR1gW.js} +2 -2
  2. package/dist/cjs/_rollupPluginBabelHelpers-Db0KR1gW.js.map +1 -0
  3. package/dist/cjs/hooks/index.js +2 -2
  4. package/dist/cjs/hooks/useBattery/useBattery.js +2 -2
  5. package/dist/cjs/hooks/useBoolean/useBoolean.js +2 -2
  6. package/dist/cjs/hooks/useClickOutside/useClickOutside.js +1 -1
  7. package/dist/cjs/hooks/useCopyToClipboard/useCopyToClipboard.js +2 -2
  8. package/dist/cjs/hooks/useCounter/useCounter.js +2 -2
  9. package/dist/cjs/hooks/useCounter/useCounter.js.map +1 -1
  10. package/dist/cjs/hooks/useDebouncedValue/useDebouncedValue.js +2 -2
  11. package/dist/cjs/hooks/useDebouncedValue/useDebouncedValue.js.map +1 -1
  12. package/dist/cjs/hooks/useDefault/useDefault.js +3 -0
  13. package/dist/cjs/hooks/useDefault/useDefault.js.map +1 -0
  14. package/dist/cjs/hooks/useDidUpdate/useDidUpdate.js +3 -0
  15. package/dist/cjs/hooks/useDidUpdate/useDidUpdate.js.map +1 -0
  16. package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.js +2 -2
  17. package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.js +1 -1
  18. package/dist/cjs/hooks/useEventListener/useEventListener.js +1 -1
  19. package/dist/cjs/hooks/useEventListener/useEventListener.js.map +1 -1
  20. package/dist/cjs/hooks/useFavicon/useFavicon.js +3 -0
  21. package/dist/cjs/hooks/useFavicon/useFavicon.js.map +1 -0
  22. package/dist/cjs/hooks/useHash/useHash.js +3 -0
  23. package/dist/cjs/hooks/useHash/useHash.js.map +1 -0
  24. package/dist/cjs/hooks/useHover/useHover.js +2 -2
  25. package/dist/cjs/hooks/useHover/useHover.js.map +1 -1
  26. package/dist/cjs/hooks/useIdle/useIdle.js +3 -0
  27. package/dist/cjs/hooks/useIdle/useIdle.js.map +1 -0
  28. package/dist/cjs/hooks/useIsFirstRender/useIsFirstRender.js +3 -0
  29. package/dist/cjs/hooks/useIsFirstRender/useIsFirstRender.js.map +1 -0
  30. package/dist/cjs/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +1 -1
  31. package/dist/cjs/hooks/useKeyPress/useKeyPress.js +2 -2
  32. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.js +1 -1
  33. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.js +2 -2
  34. package/dist/cjs/hooks/useLocalStorage/useLocalStorage.js +2 -2
  35. package/dist/cjs/hooks/useLocalStorage/useLocalStorage.js.map +1 -1
  36. package/dist/cjs/hooks/useLogger/useLogger.js +3 -0
  37. package/dist/cjs/hooks/useLogger/useLogger.js.map +1 -0
  38. package/dist/cjs/hooks/useMediaQuery/useMediaQuery.js +3 -0
  39. package/dist/cjs/hooks/useMediaQuery/useMediaQuery.js.map +1 -0
  40. package/dist/cjs/hooks/useMount/useMount.js +1 -1
  41. package/dist/cjs/hooks/useMount/useMount.js.map +1 -1
  42. package/dist/cjs/hooks/useMutationObserver.js +1 -1
  43. package/dist/cjs/hooks/useNetwork/useNetwork.js +2 -2
  44. package/dist/cjs/hooks/useNetwork/useNetwork.js.map +1 -1
  45. package/dist/cjs/hooks/useOnline/useOnline.js +1 -1
  46. package/dist/cjs/hooks/useOnline/useOnline.js.map +1 -1
  47. package/dist/cjs/hooks/useOperatingSystem/useOperatingSystem.js +3 -0
  48. package/dist/cjs/hooks/useOperatingSystem/useOperatingSystem.js.map +1 -0
  49. package/dist/cjs/hooks/useOrientation/useOrientation.js +2 -2
  50. package/dist/cjs/hooks/useOrientation/useOrientation.js.map +1 -1
  51. package/dist/cjs/hooks/usePrevious/usePrevious.js +3 -0
  52. package/dist/cjs/hooks/usePrevious/usePrevious.js.map +1 -0
  53. package/dist/cjs/hooks/useRenderCount/useRenderCount.js +1 -1
  54. package/dist/cjs/hooks/useRerender/useRerender.js +3 -0
  55. package/dist/cjs/hooks/useRerender/useRerender.js.map +1 -0
  56. package/dist/cjs/hooks/useScript/useScript.js +3 -0
  57. package/dist/cjs/hooks/useScript/useScript.js.map +1 -0
  58. package/dist/cjs/hooks/useSessionStorage/useSessionStorage.js +2 -2
  59. package/dist/cjs/hooks/useSessionStorage/useSessionStorage.js.map +1 -1
  60. package/dist/cjs/hooks/useSet/useSet.js +3 -0
  61. package/dist/cjs/hooks/useSet/useSet.js.map +1 -0
  62. package/dist/cjs/hooks/useStep/useStep.js +2 -2
  63. package/dist/cjs/hooks/useStep/useStep.js.map +1 -1
  64. package/dist/cjs/hooks/useStorage/useStorage.js +2 -2
  65. package/dist/cjs/hooks/useStorage/useStorage.js.map +1 -1
  66. package/dist/cjs/hooks/useTimeout/useTimeout.js +2 -2
  67. package/dist/cjs/hooks/useToggle/useToggle.js +2 -2
  68. package/dist/cjs/hooks/useToggle/useToggle.js.map +1 -1
  69. package/dist/cjs/hooks/useUnmount/useUnmount.js +1 -1
  70. package/dist/cjs/hooks/useUnmount/useUnmount.js.map +1 -1
  71. package/dist/cjs/hooks/useWindowEvent/useWindowEvent.js +1 -1
  72. package/dist/cjs/hooks/useWindowSize/useWindowSize.js +2 -2
  73. package/dist/cjs/index.js +2 -2
  74. package/dist/cjs/utils/helpers/debounce.js +1 -1
  75. package/dist/cjs/utils/helpers/index.js +2 -2
  76. package/dist/cjs/utils/helpers/isClient.js +1 -1
  77. package/dist/cjs/utils/helpers/isShallowEqual.js +1 -1
  78. package/dist/cjs/utils/helpers/throttle.js +3 -0
  79. package/dist/cjs/utils/helpers/throttle.js.map +1 -0
  80. package/dist/esm/{_rollupPluginBabelHelpers-8YyPIzj_.js → _rollupPluginBabelHelpers-Cg3Jntln.js} +2 -2
  81. package/dist/esm/_rollupPluginBabelHelpers-Cg3Jntln.js.map +1 -0
  82. package/dist/esm/hooks/index.js +2 -2
  83. package/dist/esm/hooks/useBattery/useBattery.js +2 -2
  84. package/dist/esm/hooks/useBoolean/useBoolean.js +2 -2
  85. package/dist/esm/hooks/useClickOutside/useClickOutside.js +1 -1
  86. package/dist/esm/hooks/useCopyToClipboard/useCopyToClipboard.js +2 -2
  87. package/dist/esm/hooks/useCounter/useCounter.js +2 -2
  88. package/dist/esm/hooks/useCounter/useCounter.js.map +1 -1
  89. package/dist/esm/hooks/useDebouncedValue/useDebouncedValue.js +2 -2
  90. package/dist/esm/hooks/useDebouncedValue/useDebouncedValue.js.map +1 -1
  91. package/dist/esm/hooks/useDefault/useDefault.js +3 -0
  92. package/dist/esm/hooks/useDefault/useDefault.js.map +1 -0
  93. package/dist/esm/hooks/{useNonInitialEffect/useNonInitialEffect.js → useDidUpdate/useDidUpdate.js} +3 -3
  94. package/dist/esm/hooks/useDidUpdate/useDidUpdate.js.map +1 -0
  95. package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.js +2 -2
  96. package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.js +1 -1
  97. package/dist/esm/hooks/useEventListener/useEventListener.js +1 -1
  98. package/dist/esm/hooks/useEventListener/useEventListener.js.map +1 -1
  99. package/dist/esm/hooks/useFavicon/useFavicon.js +3 -0
  100. package/dist/esm/hooks/useFavicon/useFavicon.js.map +1 -0
  101. package/dist/esm/hooks/useHash/useHash.js +3 -0
  102. package/dist/esm/hooks/useHash/useHash.js.map +1 -0
  103. package/dist/esm/hooks/useHover/useHover.js +2 -2
  104. package/dist/esm/hooks/useHover/useHover.js.map +1 -1
  105. package/dist/esm/hooks/useIdle/useIdle.js +3 -0
  106. package/dist/esm/hooks/useIdle/useIdle.js.map +1 -0
  107. package/dist/esm/hooks/useIsFirstRender/useIsFirstRender.js +3 -0
  108. package/dist/esm/hooks/useIsFirstRender/useIsFirstRender.js.map +1 -0
  109. package/dist/esm/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +1 -1
  110. package/dist/esm/hooks/useKeyPress/useKeyPress.js +2 -2
  111. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.js +1 -1
  112. package/dist/esm/hooks/useKeysPressed/useKeysPressed.js +2 -2
  113. package/dist/esm/hooks/useLocalStorage/useLocalStorage.js +2 -2
  114. package/dist/esm/hooks/useLocalStorage/useLocalStorage.js.map +1 -1
  115. package/dist/esm/hooks/useLogger/useLogger.js +3 -0
  116. package/dist/esm/hooks/useLogger/useLogger.js.map +1 -0
  117. package/dist/esm/hooks/useMediaQuery/useMediaQuery.js +3 -0
  118. package/dist/esm/hooks/useMediaQuery/useMediaQuery.js.map +1 -0
  119. package/dist/esm/hooks/useMount/useMount.js +1 -1
  120. package/dist/esm/hooks/useMount/useMount.js.map +1 -1
  121. package/dist/esm/hooks/useMutationObserver.js +1 -1
  122. package/dist/esm/hooks/useNetwork/useNetwork.js +2 -2
  123. package/dist/esm/hooks/useNetwork/useNetwork.js.map +1 -1
  124. package/dist/esm/hooks/useOnline/useOnline.js +1 -1
  125. package/dist/esm/hooks/useOnline/useOnline.js.map +1 -1
  126. package/dist/esm/hooks/useOperatingSystem/useOperatingSystem.js +3 -0
  127. package/dist/esm/hooks/useOperatingSystem/useOperatingSystem.js.map +1 -0
  128. package/dist/esm/hooks/useOrientation/useOrientation.js +2 -2
  129. package/dist/esm/hooks/useOrientation/useOrientation.js.map +1 -1
  130. package/dist/esm/hooks/usePrevious/usePrevious.js +3 -0
  131. package/dist/esm/hooks/usePrevious/usePrevious.js.map +1 -0
  132. package/dist/esm/hooks/useRenderCount/useRenderCount.js +1 -1
  133. package/dist/esm/hooks/useRerender/useRerender.js +3 -0
  134. package/dist/esm/hooks/useRerender/useRerender.js.map +1 -0
  135. package/dist/esm/hooks/useScript/useScript.js +3 -0
  136. package/dist/esm/hooks/useScript/useScript.js.map +1 -0
  137. package/dist/esm/hooks/useSessionStorage/useSessionStorage.js +2 -2
  138. package/dist/esm/hooks/useSessionStorage/useSessionStorage.js.map +1 -1
  139. package/dist/esm/hooks/useSet/useSet.js +3 -0
  140. package/dist/esm/hooks/useSet/useSet.js.map +1 -0
  141. package/dist/esm/hooks/useStep/useStep.js +2 -2
  142. package/dist/esm/hooks/useStep/useStep.js.map +1 -1
  143. package/dist/esm/hooks/useStorage/useStorage.js +2 -2
  144. package/dist/esm/hooks/useStorage/useStorage.js.map +1 -1
  145. package/dist/esm/hooks/useTimeout/useTimeout.js +2 -2
  146. package/dist/esm/hooks/useToggle/useToggle.js +2 -2
  147. package/dist/esm/hooks/useToggle/useToggle.js.map +1 -1
  148. package/dist/esm/hooks/useUnmount/useUnmount.js +1 -1
  149. package/dist/esm/hooks/useUnmount/useUnmount.js.map +1 -1
  150. package/dist/esm/hooks/useWindowEvent/useWindowEvent.js +1 -1
  151. package/dist/esm/hooks/useWindowSize/useWindowSize.js +2 -2
  152. package/dist/esm/index.js +2 -2
  153. package/dist/esm/utils/helpers/debounce.js +1 -1
  154. package/dist/esm/utils/helpers/index.js +2 -2
  155. package/dist/esm/utils/helpers/isClient.js +1 -1
  156. package/dist/esm/utils/helpers/isShallowEqual.js +1 -1
  157. package/dist/esm/utils/helpers/throttle.js +3 -0
  158. package/dist/esm/utils/helpers/throttle.js.map +1 -0
  159. package/dist/index.d.ts +252 -29
  160. package/package.json +1 -1
  161. package/dist/cjs/_rollupPluginBabelHelpers-Cva0m6Ep.js.map +0 -1
  162. package/dist/cjs/hooks/useNonInitialEffect/useNonInitialEffect.js +0 -3
  163. package/dist/cjs/hooks/useNonInitialEffect/useNonInitialEffect.js.map +0 -1
  164. package/dist/esm/_rollupPluginBabelHelpers-8YyPIzj_.js.map +0 -1
  165. 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 useDebouncedValue
133
- * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities
137
+ * @name useDefault
138
+ * @description - Hook that returns the default value
134
139
  *
135
- * @param {any} value fix me
136
- * @param {number} delay The delay in milliseconds
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 { count, dec, inc, reset, set } = useCounter(5);
146
+ * const [value, setValue] = useDefault(initialValue, defaultValue);
140
147
  */
141
- declare const useDebouncedValue: <Value>(value: Value, delay: number, options?: UseDebouncedValueOptions) => readonly [Value, (value: Value) => void];
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 useEventListener
190
- * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities
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 { count, dec, inc, reset, set } = useCounter(5);
228
+ * const { href, set } = useFavicon('https://www.google.com/favicon.ico');
194
229
  */
195
- declare const useEventListener: UseEventListener;
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 useStorage
312
- * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities
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
- * text
407
+ * useLogger('Component', [1, 2, 3]);
316
408
  */
317
- declare const useStorage: <Value>(key: string, params?: UseStorageInitialValue<Value> | UseStorageOptions<Value>) => readonly [Value | undefined, (value: Value) => void, () => void];
409
+ declare const useLogger: (name: string, params: unknown[]) => void;
318
410
 
319
- declare const useLocalStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) => readonly [Value | undefined, (value: Value) => void, () => void];
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 useNonInitialEffect
356
- * @description Hook that behaves like useEffect, but skips the effect on the initial render
466
+ * @name useOnline
467
+ * @description - Hook that manages if the user is online
357
468
  *
358
- * @param {React.EffectCallback} effect The effect callback
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
- * useNonInitialEffect(() => {
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
- declare const useOrientation: () => {
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
- declare const useSessionStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) => readonly [Value | undefined, (value: Value) => void, () => void];
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('Component unmounted'));
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, useNonInitialEffect, useOnline, useOrientation, useRenderCount, useSessionStorage, useStep, useStorage, useTimeout, useToggle, useUnmount, useWindowEvent, useWindowSize };
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Ultimate tool",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -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"}