@siberiacancode/reactuse 0.0.1

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 (152) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/dist/cjs/_rollupPluginBabelHelpers-9eGFsb-q.js +3 -0
  4. package/dist/cjs/_rollupPluginBabelHelpers-9eGFsb-q.js.map +1 -0
  5. package/dist/cjs/hooks/index.js +3 -0
  6. package/dist/cjs/hooks/index.js.map +1 -0
  7. package/dist/cjs/hooks/useBoolean/useBoolean.js +3 -0
  8. package/dist/cjs/hooks/useBoolean/useBoolean.js.map +1 -0
  9. package/dist/cjs/hooks/useClickOutside/useClickOutside.js +3 -0
  10. package/dist/cjs/hooks/useClickOutside/useClickOutside.js.map +1 -0
  11. package/dist/cjs/hooks/useCopyToClipboard/useCopyToClipboard.js +3 -0
  12. package/dist/cjs/hooks/useCopyToClipboard/useCopyToClipboard.js.map +1 -0
  13. package/dist/cjs/hooks/useCounter/useCounter.js +3 -0
  14. package/dist/cjs/hooks/useCounter/useCounter.js.map +1 -0
  15. package/dist/cjs/hooks/useDebouncedValue/useDebouncedValue.js +3 -0
  16. package/dist/cjs/hooks/useDebouncedValue/useDebouncedValue.js.map +1 -0
  17. package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.js +3 -0
  18. package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.js.map +1 -0
  19. package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.js +3 -0
  20. package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.js.map +1 -0
  21. package/dist/cjs/hooks/useEventListener/useEventListener.js +3 -0
  22. package/dist/cjs/hooks/useEventListener/useEventListener.js.map +1 -0
  23. package/dist/cjs/hooks/useHover/useHover.js +3 -0
  24. package/dist/cjs/hooks/useHover/useHover.js.map +1 -0
  25. package/dist/cjs/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +3 -0
  26. package/dist/cjs/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js.map +1 -0
  27. package/dist/cjs/hooks/useKeyPress/useKeyPress.js +3 -0
  28. package/dist/cjs/hooks/useKeyPress/useKeyPress.js.map +1 -0
  29. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.js +3 -0
  30. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.js.map +1 -0
  31. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.js +3 -0
  32. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.js.map +1 -0
  33. package/dist/cjs/hooks/useLocalStorage/useLocalStorage.js +3 -0
  34. package/dist/cjs/hooks/useLocalStorage/useLocalStorage.js.map +1 -0
  35. package/dist/cjs/hooks/useMount/useMount.js +3 -0
  36. package/dist/cjs/hooks/useMount/useMount.js.map +1 -0
  37. package/dist/cjs/hooks/useMutationObserver.js +3 -0
  38. package/dist/cjs/hooks/useMutationObserver.js.map +1 -0
  39. package/dist/cjs/hooks/useNetwork/useNetwork.js +3 -0
  40. package/dist/cjs/hooks/useNetwork/useNetwork.js.map +1 -0
  41. package/dist/cjs/hooks/useNonInitialEffect/useNonInitialEffect.js +3 -0
  42. package/dist/cjs/hooks/useNonInitialEffect/useNonInitialEffect.js.map +1 -0
  43. package/dist/cjs/hooks/useOnline/useOnline.js +3 -0
  44. package/dist/cjs/hooks/useOnline/useOnline.js.map +1 -0
  45. package/dist/cjs/hooks/useOrientation/useOrientation.js +3 -0
  46. package/dist/cjs/hooks/useOrientation/useOrientation.js.map +1 -0
  47. package/dist/cjs/hooks/useRenderCount/useRenderCount.js +3 -0
  48. package/dist/cjs/hooks/useRenderCount/useRenderCount.js.map +1 -0
  49. package/dist/cjs/hooks/useSessionStorage/useSessionStorage.js +3 -0
  50. package/dist/cjs/hooks/useSessionStorage/useSessionStorage.js.map +1 -0
  51. package/dist/cjs/hooks/useStorage/useStorage.js +3 -0
  52. package/dist/cjs/hooks/useStorage/useStorage.js.map +1 -0
  53. package/dist/cjs/hooks/useTimeout/useTimeout.js +3 -0
  54. package/dist/cjs/hooks/useTimeout/useTimeout.js.map +1 -0
  55. package/dist/cjs/hooks/useToggle.js +3 -0
  56. package/dist/cjs/hooks/useToggle.js.map +1 -0
  57. package/dist/cjs/hooks/useUnmount/useUnmount.js +3 -0
  58. package/dist/cjs/hooks/useUnmount/useUnmount.js.map +1 -0
  59. package/dist/cjs/hooks/useWindowEvent/useWindowEvent.js +3 -0
  60. package/dist/cjs/hooks/useWindowEvent/useWindowEvent.js.map +1 -0
  61. package/dist/cjs/hooks/useWindowSize/useWindowSize.js +3 -0
  62. package/dist/cjs/hooks/useWindowSize/useWindowSize.js.map +1 -0
  63. package/dist/cjs/index.js +3 -0
  64. package/dist/cjs/index.js.map +1 -0
  65. package/dist/cjs/utils/helpers/debounce.js +3 -0
  66. package/dist/cjs/utils/helpers/debounce.js.map +1 -0
  67. package/dist/cjs/utils/helpers/index.js +3 -0
  68. package/dist/cjs/utils/helpers/index.js.map +1 -0
  69. package/dist/cjs/utils/helpers/isClient.js +3 -0
  70. package/dist/cjs/utils/helpers/isClient.js.map +1 -0
  71. package/dist/cjs/utils/helpers/isShallowEqual.js +3 -0
  72. package/dist/cjs/utils/helpers/isShallowEqual.js.map +1 -0
  73. package/dist/cjs/utils/tests/index.js +3 -0
  74. package/dist/cjs/utils/tests/index.js.map +1 -0
  75. package/dist/cjs/utils/tests/renderHookServer.js +88 -0
  76. package/dist/cjs/utils/tests/renderHookServer.js.map +1 -0
  77. package/dist/esm/_rollupPluginBabelHelpers-BDc6tlcX.js +3 -0
  78. package/dist/esm/_rollupPluginBabelHelpers-BDc6tlcX.js.map +1 -0
  79. package/dist/esm/hooks/index.js +3 -0
  80. package/dist/esm/hooks/index.js.map +1 -0
  81. package/dist/esm/hooks/useBoolean/useBoolean.js +3 -0
  82. package/dist/esm/hooks/useBoolean/useBoolean.js.map +1 -0
  83. package/dist/esm/hooks/useClickOutside/useClickOutside.js +3 -0
  84. package/dist/esm/hooks/useClickOutside/useClickOutside.js.map +1 -0
  85. package/dist/esm/hooks/useCopyToClipboard/useCopyToClipboard.js +3 -0
  86. package/dist/esm/hooks/useCopyToClipboard/useCopyToClipboard.js.map +1 -0
  87. package/dist/esm/hooks/useCounter/useCounter.js +3 -0
  88. package/dist/esm/hooks/useCounter/useCounter.js.map +1 -0
  89. package/dist/esm/hooks/useDebouncedValue/useDebouncedValue.js +3 -0
  90. package/dist/esm/hooks/useDebouncedValue/useDebouncedValue.js.map +1 -0
  91. package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.js +3 -0
  92. package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.js.map +1 -0
  93. package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.js +3 -0
  94. package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.js.map +1 -0
  95. package/dist/esm/hooks/useEventListener/useEventListener.js +3 -0
  96. package/dist/esm/hooks/useEventListener/useEventListener.js.map +1 -0
  97. package/dist/esm/hooks/useHover/useHover.js +3 -0
  98. package/dist/esm/hooks/useHover/useHover.js.map +1 -0
  99. package/dist/esm/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +3 -0
  100. package/dist/esm/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js.map +1 -0
  101. package/dist/esm/hooks/useKeyPress/useKeyPress.js +3 -0
  102. package/dist/esm/hooks/useKeyPress/useKeyPress.js.map +1 -0
  103. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.js +3 -0
  104. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.js.map +1 -0
  105. package/dist/esm/hooks/useKeysPressed/useKeysPressed.js +3 -0
  106. package/dist/esm/hooks/useKeysPressed/useKeysPressed.js.map +1 -0
  107. package/dist/esm/hooks/useLocalStorage/useLocalStorage.js +3 -0
  108. package/dist/esm/hooks/useLocalStorage/useLocalStorage.js.map +1 -0
  109. package/dist/esm/hooks/useMount/useMount.js +3 -0
  110. package/dist/esm/hooks/useMount/useMount.js.map +1 -0
  111. package/dist/esm/hooks/useMutationObserver.js +3 -0
  112. package/dist/esm/hooks/useMutationObserver.js.map +1 -0
  113. package/dist/esm/hooks/useNetwork/useNetwork.js +3 -0
  114. package/dist/esm/hooks/useNetwork/useNetwork.js.map +1 -0
  115. package/dist/esm/hooks/useNonInitialEffect/useNonInitialEffect.js +3 -0
  116. package/dist/esm/hooks/useNonInitialEffect/useNonInitialEffect.js.map +1 -0
  117. package/dist/esm/hooks/useOnline/useOnline.js +3 -0
  118. package/dist/esm/hooks/useOnline/useOnline.js.map +1 -0
  119. package/dist/esm/hooks/useOrientation/useOrientation.js +3 -0
  120. package/dist/esm/hooks/useOrientation/useOrientation.js.map +1 -0
  121. package/dist/esm/hooks/useRenderCount/useRenderCount.js +3 -0
  122. package/dist/esm/hooks/useRenderCount/useRenderCount.js.map +1 -0
  123. package/dist/esm/hooks/useSessionStorage/useSessionStorage.js +3 -0
  124. package/dist/esm/hooks/useSessionStorage/useSessionStorage.js.map +1 -0
  125. package/dist/esm/hooks/useStorage/useStorage.js +3 -0
  126. package/dist/esm/hooks/useStorage/useStorage.js.map +1 -0
  127. package/dist/esm/hooks/useTimeout/useTimeout.js +3 -0
  128. package/dist/esm/hooks/useTimeout/useTimeout.js.map +1 -0
  129. package/dist/esm/hooks/useToggle.js +3 -0
  130. package/dist/esm/hooks/useToggle.js.map +1 -0
  131. package/dist/esm/hooks/useUnmount/useUnmount.js +3 -0
  132. package/dist/esm/hooks/useUnmount/useUnmount.js.map +1 -0
  133. package/dist/esm/hooks/useWindowEvent/useWindowEvent.js +3 -0
  134. package/dist/esm/hooks/useWindowEvent/useWindowEvent.js.map +1 -0
  135. package/dist/esm/hooks/useWindowSize/useWindowSize.js +3 -0
  136. package/dist/esm/hooks/useWindowSize/useWindowSize.js.map +1 -0
  137. package/dist/esm/index.js +3 -0
  138. package/dist/esm/index.js.map +1 -0
  139. package/dist/esm/utils/helpers/debounce.js +3 -0
  140. package/dist/esm/utils/helpers/debounce.js.map +1 -0
  141. package/dist/esm/utils/helpers/index.js +3 -0
  142. package/dist/esm/utils/helpers/index.js.map +1 -0
  143. package/dist/esm/utils/helpers/isClient.js +3 -0
  144. package/dist/esm/utils/helpers/isClient.js.map +1 -0
  145. package/dist/esm/utils/helpers/isShallowEqual.js +3 -0
  146. package/dist/esm/utils/helpers/isShallowEqual.js.map +1 -0
  147. package/dist/esm/utils/tests/index.js +3 -0
  148. package/dist/esm/utils/tests/index.js.map +1 -0
  149. package/dist/esm/utils/tests/renderHookServer.js +88 -0
  150. package/dist/esm/utils/tests/renderHookServer.js.map +1 -0
  151. package/dist/index.d.ts +338 -0
  152. package/package.json +97 -0
@@ -0,0 +1,338 @@
1
+ import React from 'react';
2
+
3
+ /** The use boolean return type */
4
+ type UseBooleanReturn = [
5
+ /** The current boolean state value */
6
+ value: boolean,
7
+ /** Function to toggle the boolean state */
8
+ toggle: (value?: boolean) => void
9
+ ];
10
+ /**
11
+ * @name useBoolean
12
+ * @description - Hook provides a boolean state and a function to toggle the boolean value
13
+ *
14
+ * @param {boolean} [initialValue=false] The initial boolean value
15
+ * @returns {UseBooleanReturn} An object containing the boolean state value and utility functions to manipulate the state
16
+ *
17
+ * @example
18
+ * const [on, toggle] = useBoolean()
19
+ */
20
+ declare const useBoolean: (initialValue?: boolean) => UseBooleanReturn;
21
+
22
+ type UseClickOutsideTarget = React.RefObject<Element | null> | (() => Element) | Element;
23
+ type UseClickOutsideReturn<Target extends UseClickOutsideTarget | Array<UseClickOutsideTarget> = any> = React.RefObject<Target>;
24
+ type UseClickOutside = {
25
+ <Target extends UseClickOutsideTarget | Array<UseClickOutsideTarget> = any>(target: Target, callback: (event: Event) => void): void;
26
+ <Target extends UseClickOutsideTarget | Array<UseClickOutsideTarget> = any>(callback: (event: Event) => void, target?: never): UseClickOutsideReturn<Target>;
27
+ };
28
+ /**
29
+ * @name useClickOutside
30
+ * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities
31
+ *
32
+ * @example
33
+ * const { count, dec, inc, reset, set } = useCounter(5);
34
+ */
35
+ declare const useClickOutside: UseClickOutside;
36
+
37
+ declare const legacyCopyToClipboard: (value: string) => void;
38
+ /** The use copy to clipboard return type */
39
+ type UseCopyToClipboardReturn = [
40
+ /** The copied value */
41
+ value: string | null,
42
+ /** Function to copy to clipboard */
43
+ copyToClipboard: (value: string) => Promise<void>
44
+ ];
45
+ /**
46
+ * @name useCopyToClipboard
47
+ * @description - Hook that manages a copy to clipboard
48
+ *
49
+ * @returns {UseCopyToClipboardReturn} An object containing the boolean state value and utility functions to manipulate the state
50
+ *
51
+ * @example
52
+ * const [copiedText, copyToClipboard] = useCopyToClipboard();
53
+ */
54
+ declare const useCopyToClipboard: () => UseCopyToClipboardReturn;
55
+
56
+ /** The use counter options */
57
+ interface UseCounterOptions {
58
+ /** The min of count value */
59
+ min?: number;
60
+ /** The max of count value */
61
+ max?: number;
62
+ }
63
+ interface UseCounterParams {
64
+ /** The initial number value, defaults to 0 */
65
+ initialValue?: number;
66
+ /** The min of count value */
67
+ min?: number;
68
+ /** The max of count value */
69
+ max?: number;
70
+ }
71
+ /** The use counter return type */
72
+ interface UseCounterReturn {
73
+ /** The current count value */
74
+ count: number;
75
+ /** Function to set a specific value to the counter */
76
+ set: React.Dispatch<React.SetStateAction<number>>;
77
+ /** Function to reset the counter to its initial value. */
78
+ reset: () => void;
79
+ /** Function to increment the counter */
80
+ inc: (value?: number) => void;
81
+ /** Function to decrement the counter */
82
+ dec: (value?: number) => void;
83
+ }
84
+ type UseCounter = {
85
+ (initialValue?: number, options?: UseCounterOptions): UseCounterReturn;
86
+ ({ initialValue, max, min }: UseCounterParams, options?: never): UseCounterReturn;
87
+ };
88
+ /**
89
+ * @name useCounter
90
+ * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities
91
+ *
92
+ * @overload
93
+ * @param {number} [initialValue=0] The initial number value
94
+ * @param {UseCounterOptions} [useCounterOptions] The use counter options
95
+ * @returns {UseCounterReturn} An object containing the current count and functions to interact with the counter
96
+
97
+ * @overload
98
+ * @param {UseCounterParams} [useCounterParams] The use counter params
99
+ * @returns {UseCounterReturn} An object containing the current count and functions to interact with the counter
100
+ *
101
+ * @example
102
+ * const { count, dec, inc, reset, set } = useCounter(5);
103
+ */
104
+ declare const useCounter: UseCounter;
105
+
106
+ interface UseDebouncedValueOptions {
107
+ maxWait?: number;
108
+ }
109
+ /**
110
+ * @name useDebouncedValue
111
+ * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities
112
+ *
113
+ * @param {any} value fix me
114
+ * @param {number} delay The delay in milliseconds
115
+ *
116
+ * @example
117
+ * const { count, dec, inc, reset, set } = useCounter(5);
118
+ */
119
+ declare const useDebouncedValue: <Value>(value: Value, delay: number, options?: UseDebouncedValueOptions) => readonly [Value, (value: Value) => void];
120
+
121
+ interface UseDocumentTitleOptions {
122
+ /** Restore the previous title on unmount */
123
+ restoreOnUnmount?: boolean;
124
+ }
125
+ type UseDocumentTitleReturn = [
126
+ /** The current title */
127
+ title: string,
128
+ /** Function to update the title */
129
+ setTitle: (title: string) => void
130
+ ];
131
+ /**
132
+ * @name useDocumentTitle
133
+ * @description - Hook that manages the document title and allows updating it
134
+ *
135
+ * @param {string} [value] The initial title. If not provided, the current document title will be used
136
+ * @param {UseDocumentTitleOptions} [options] The use document title options
137
+ * @returns {UseDocumentTitleReturn} An array containing the current title and a function to update the title
138
+ *
139
+ * @example
140
+ * const [title, setTitle] = useDocumentTitle();
141
+ */
142
+ declare function useDocumentTitle(value?: string, options?: UseDocumentTitleOptions): UseDocumentTitleReturn;
143
+
144
+ declare const useDocumentVisibility: () => DocumentVisibilityState;
145
+
146
+ type UseEventListenerTarget = React.RefObject<Element | null> | (() => Element) | Element | Window | Document;
147
+ type UseEventListenerOptions = boolean | AddEventListenerOptions;
148
+ type UseEventListenerReturn<Target extends UseEventListenerTarget = any> = React.RefObject<Target>;
149
+ type UseEventListener = {
150
+ <Event extends keyof WindowEventMap = keyof WindowEventMap>(target: Window, event: Event, listener: (this: Window, event: WindowEventMap[Event]) => void, options?: UseEventListenerOptions): void;
151
+ <Event extends keyof DocumentEventMap = keyof DocumentEventMap>(target: Document, event: Event, listener: (this: Document, event: DocumentEventMap[Event]) => void, options?: UseEventListenerOptions): void;
152
+ <Target extends UseEventListenerTarget, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(target: Target, event: Event, listener: (this: Target, event: HTMLElementEventMap[Event]) => void, options?: UseEventListenerOptions): void;
153
+ <Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(event: Event, listener: (this: Target, event: HTMLElementEventMap[Event]) => void, options?: UseEventListenerOptions, target?: never): UseEventListenerReturn<Target>;
154
+ };
155
+ /**
156
+ * @name useEventListener
157
+ * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities
158
+ *
159
+ * @example
160
+ * const { count, dec, inc, reset, set } = useCounter(5);
161
+ */
162
+ declare const useEventListener: UseEventListener;
163
+
164
+ type UseHoverTarget = React.RefObject<Element | null> | Element;
165
+ type UseHoverReturn<Target extends UseHoverTarget = any> = [
166
+ React.RefObject<Target>,
167
+ boolean
168
+ ];
169
+ type UseHover = {
170
+ <Target extends UseHoverTarget>(target: Target, callback?: () => void): boolean;
171
+ <Target extends UseHoverTarget>(callback?: () => void, target?: never): UseHoverReturn<Target>;
172
+ };
173
+ /**
174
+ * @name useHover
175
+ * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities
176
+ *
177
+ * @example
178
+ * const { count, dec, inc, reset, set } = useCounter(5);
179
+ */
180
+ declare const useHover: UseHover;
181
+
182
+ /**
183
+ * @name useIsomorphicLayoutEffect
184
+ * @description - Hook conditionally selects either `useLayoutEffect` or `useEffect` based on the environment
185
+ *
186
+ * @example
187
+ * useIsomorphicLayoutEffect(() => console.log('effect'), [])
188
+ */
189
+ declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
190
+
191
+ type UseKeyPressKey = string | string[];
192
+ type UseKeyPressOptions = {
193
+ target: UseEventListenerTarget;
194
+ };
195
+ declare const useKeyPress: (key: UseKeyPressKey, options?: UseKeyPressOptions) => boolean;
196
+
197
+ type UseKeyPressEventKey = string | string[];
198
+ type UseKeyPressEvent = {
199
+ (key: UseKeyPressEventKey, target: Window, listener: (this: Window, event: WindowEventMap['keydown']) => void, options?: UseEventListenerOptions): void;
200
+ (key: UseKeyPressEventKey, target: Document, listener: (this: Document, event: DocumentEventMap['keydown']) => void, options?: UseEventListenerOptions): void;
201
+ <Target extends UseEventListenerTarget>(key: UseKeyPressEventKey, target: Target, listener: (this: Target, event: HTMLElementEventMap['keydown']) => void, options?: UseEventListenerOptions): void;
202
+ <Target extends Element>(key: UseKeyPressEventKey, listener: (this: Target, event: HTMLElementEventMap['keydown']) => void, options?: UseEventListenerOptions, target?: never): void;
203
+ };
204
+ declare const useKeyPressEvent: UseKeyPressEvent;
205
+
206
+ declare const useKeysPressed: (target?: UseEventListenerTarget) => string[];
207
+
208
+ type UseStorageInitialValue<Value> = Value | (() => Value);
209
+ interface UseStorageOptions<Value> {
210
+ serializer?: (value: Value) => string;
211
+ deserializer?: (value: string) => Value;
212
+ storage: Storage;
213
+ }
214
+ declare const dispatchStorageEvent: (params: Partial<StorageEvent>) => boolean;
215
+ /**
216
+ * @name useStorage
217
+ * @description - Hook that manages a counter with increment, decrement, reset, and set functionalities
218
+ *
219
+ * @example
220
+ * text
221
+ */
222
+ declare function useStorage<Value = string | null>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>): {
223
+ value: Value;
224
+ set: (value: Value) => void;
225
+ clear: () => void;
226
+ };
227
+
228
+ declare const useLocalStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) => {
229
+ value: Value;
230
+ set: (value: Value) => void;
231
+ clear: () => void;
232
+ };
233
+
234
+ declare const useMount: (effect: React.EffectCallback) => void;
235
+
236
+ type ConnectionType = Connection['type'];
237
+ type ConnectionEffectiveType = Connection['effectiveType'];
238
+ interface UseNetworkReturn {
239
+ online: boolean;
240
+ downlink?: Connection['downlink'];
241
+ downlinkMax?: Connection['downlinkMax'];
242
+ effectiveType?: Connection['effectiveType'];
243
+ rtt?: Connection['rtt'];
244
+ saveData?: Connection['saveData'];
245
+ type?: Connection['type'];
246
+ }
247
+ declare const getConnection: () => Connection;
248
+ declare const useNetwork: () => UseNetworkReturn;
249
+
250
+ declare const useNonInitialEffect: (effect: React.EffectCallback, deps?: React.DependencyList) => void;
251
+
252
+ declare const useOnline: () => boolean;
253
+
254
+ declare const useOrientation: () => {
255
+ angle: number;
256
+ type: OrientationType;
257
+ };
258
+
259
+ /**
260
+ * @name useRenderCount
261
+ * @description - Hook returns count component render times
262
+ *
263
+ * @returns {number} A number which determines how many times component renders
264
+ *
265
+ * @example
266
+ * const renderCount = useRenderCount();
267
+ */
268
+ declare const useRenderCount: () => number;
269
+
270
+ declare const useSessionStorage: <Value>(key: string, initialValue?: UseStorageInitialValue<Value>, options?: UseStorageOptions<Value>) => {
271
+ value: Value;
272
+ set: (value: Value) => void;
273
+ clear: () => void;
274
+ };
275
+
276
+ declare function useTimeout(callback: () => void, delay: number): {
277
+ ready: boolean;
278
+ clear: () => void;
279
+ };
280
+
281
+ /**
282
+ * @name useUnmount
283
+ * @description - Hook that defines the logic when unmounting a component
284
+ *
285
+ * @param {() => void} callback The callback function to be invoked on component unmount
286
+ *
287
+ * @returns {void}
288
+ *
289
+ * @example
290
+ * useUnmount(() => console.log('Component unmounted'));
291
+ */
292
+ declare const useUnmount: (callback: () => void) => void;
293
+
294
+ /**
295
+ * @name useWindowEvent
296
+ * @description - Hook attaches an event listener to the window object for the specified event
297
+ *
298
+ * @template Event Key of window event map.
299
+ * @param {Event} event The event to listen for.
300
+ * @param {(event: WindowEventMap[Event]) => void} listener The callback function to be executed when the event is triggered
301
+ * @param {UseEventListenerOptions} [options] The options for the event listener
302
+ * @returns {void}
303
+ *
304
+ * @example
305
+ * useWindowEvent('click', () => console.log('clicked'));
306
+ */
307
+ declare const useWindowEvent: <Event extends keyof WindowEventMap>(event: Event, listener: (this: Window, event: WindowEventMap[Event]) => any, options?: UseEventListenerOptions) => void;
308
+
309
+ /** The use window size return type */
310
+ interface UseWindowSizeParams {
311
+ /** The initial window width */
312
+ initialWidth?: number;
313
+ /** The initial window height */
314
+ initialHeight?: number;
315
+ }
316
+ /** The use window size return type */
317
+ interface UseWindowSizeReturn {
318
+ /** The current window width */
319
+ width: number;
320
+ /** The current window height */
321
+ height: number;
322
+ }
323
+ /**
324
+ * @name useWindowSize
325
+ * @description - Hook that manages a window size
326
+ *
327
+ * @param {UseWindowSizeParams} [useWindowSizeParams] The use copy to clipboard params
328
+ * @returns {UseWindowSizeReturn} An object containing the current window width and height
329
+ *
330
+ * @example
331
+ * const { width, height } = useWindowSize()
332
+ */
333
+ declare const useWindowSize: (params?: UseWindowSizeParams) => {
334
+ width: number;
335
+ height: number;
336
+ };
337
+
338
+ 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 UseHoverReturn, type UseHoverTarget, type UseKeyPressEvent, type UseKeyPressEventKey, type UseKeyPressKey, type UseKeyPressOptions, type UseNetworkReturn, type UseStorageInitialValue, type UseStorageOptions, type UseWindowSizeReturn, dispatchStorageEvent, getConnection, legacyCopyToClipboard, useBoolean, useClickOutside, useCopyToClipboard, useCounter, useDebouncedValue, useDocumentTitle, useDocumentVisibility, useEventListener, useHover, useIsomorphicLayoutEffect, useKeyPress, useKeyPressEvent, useKeysPressed, useLocalStorage, useMount, useNetwork, useNonInitialEffect, useOnline, useOrientation, useRenderCount, useSessionStorage, useStorage, useTimeout, useUnmount, useWindowEvent, useWindowSize };
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@siberiacancode/reactuse",
3
+ "version": "0.0.1",
4
+ "description": "Ultimate tool",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "SIBERIA CAN CODE 🧊",
8
+ "url": "https://github.com/siberiacancode"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "Dmitry Babin",
13
+ "url": "https://github.com/debabin"
14
+ }
15
+ ],
16
+ "engines": {
17
+ "node": ">=14"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/siberiacancode/webcam.git"
25
+ },
26
+ "homepage": "https://github.com/siberiacancode/webcam",
27
+ "bugs": "https://github.com/siberiacancode/webcam/issues",
28
+ "files": [
29
+ "dist/**/*"
30
+ ],
31
+ "main": "dist/cjs/index.js",
32
+ "module": "dist/esm/index.js",
33
+ "types": "dist/index.d.ts",
34
+ "scripts": {
35
+ "build": "shx rm -rf dist && rollup -c --bundleConfigAsCjs",
36
+ "lint": "eslint . --ext ts --ext tsx --no-error-on-unmatched-pattern --fix",
37
+ "format": "prettier --write **/*.{ts,jsm,md}",
38
+ "type": "tsc --noEmit",
39
+ "pretty": "yarn type && yarn format && yarn lint",
40
+ "prepare": "husky install",
41
+ "unit-test": "jest",
42
+ "docs:dev": "vitepress dev docs",
43
+ "docs:build": "vitepress build docs",
44
+ "docs:preview": "vitepress preview docs"
45
+ },
46
+ "lint-staged": {
47
+ "*.js": "prettier --write",
48
+ "*.ts": [
49
+ "prettier --write",
50
+ "eslint --no-error-on-unmatched-pattern --fix"
51
+ ]
52
+ },
53
+ "peerDependencies": {
54
+ "@types/react": "^18.0.0",
55
+ "react": "^17.0.2 || ^18.0.0"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "@types/react": {
59
+ "optional": true
60
+ }
61
+ },
62
+ "dependencies": {
63
+ "@webcam/core": "*"
64
+ },
65
+ "devDependencies": {
66
+ "@siberiacancode/builder": "^1.3.0",
67
+ "@siberiacancode/eslint": "^1.1.0",
68
+ "@siberiacancode/jest": "^1.0.2",
69
+ "@siberiacancode/prettier": "^1.1.0",
70
+ "@testing-library/jest-dom": "^6.4.5",
71
+ "@testing-library/react": "^15.0.7",
72
+ "@types/doctrine": "^0.0.9",
73
+ "@types/jest": "^29.5.12",
74
+ "@types/node": "^20.11.19",
75
+ "@types/react": "^18.3.2",
76
+ "@types/react-dom": "^18.3.0",
77
+ "comment-parser": "^1.4.1",
78
+ "doctrine": "^3.0.0",
79
+ "eslint": "^8.56.0",
80
+ "husky": "^9.0.11",
81
+ "lint-staged": "^15.2.2",
82
+ "markdown-table": "^3.0.3",
83
+ "react": "^18.2.0",
84
+ "react-dom": "^18.2.0",
85
+ "shx": "^0.3.4",
86
+ "typescript": "^5.3.3",
87
+ "vite": "^5.1.3",
88
+ "vitepress": "^1.1.4"
89
+ },
90
+ "keywords": [
91
+ "react",
92
+ "react hooks",
93
+ "react use",
94
+ "use",
95
+ "hooks"
96
+ ]
97
+ }