react-hook-toolkit 1.0.3 → 1.0.5

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/README.md CHANGED
@@ -1,123 +1,600 @@
1
+
1
2
  **react-hook-toolkit** package offers a comprehensive set of hooks to simplify React development. It includes hooks for managing state, handling API requests, optimizing performance, and improving user interactions. Key features include data fetching, form handling, local storage management, debouncing/throttling, window size tracking, event listeners, and more. These hooks are designed to enhance productivity by providing reusable, easy-to-use solutions for common tasks.
2
3
 
3
- ## Installation
4
+ **Note : This package is written in TypeScript and offers full support for all modern browsers.**
5
+
6
+ ### Installation
4
7
 
5
- Install the package with npm:
8
+ Install the package:
6
9
 
7
10
  ```bash
8
- npm i react-hook-toolkit
11
+ npm install react-hook-toolkit
12
+ # or
13
+ yarn add react-hook-toolkit
14
+ # or
15
+ pnpm add react-hook-toolkit
9
16
  ```
10
17
 
18
+ ### **Browser Support**
19
+
20
+ | ![Firefox](https://raw.githubusercontent.com/alrra/browser-logos/main/src/firefox/firefox_48x48.png) | ![Chrome](https://raw.githubusercontent.com/alrra/browser-logos/main/src/chrome/chrome_48x48.png) | ![Safari](https://raw.githubusercontent.com/alrra/browser-logos/main/src/safari/safari_48x48.png) | ![Opera](https://raw.githubusercontent.com/alrra/browser-logos/main/src/opera/opera_48x48.png) | ![Edge](https://raw.githubusercontent.com/alrra/browser-logos/main/src/edge/edge_48x48.png)
21
+ | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
22
+ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
23
+
11
24
  ## Features
25
+ Here's the properly structured documentation with clear purpose explanations:
26
+
27
+ ### **HOOKS** ------------------------------------------------------------------------------------------
28
+ 📌 **useAxios**
29
+ A custom hook for making API requests using Axios. It manages request states (`loading`, `error`, `data`) and provides a function (`makeRequest`) to initiate a request.
30
+ ```ts
31
+ const { data, loading, error, makeRequest, cancelRequest } = useAxios({ baseURL: '/api' });
32
+
33
+ useEffect(() => {
34
+ makeRequest('/users', 'GET');
35
+ }, []);
36
+ ```
37
+
38
+ ---
39
+
40
+ 📌 **useAdvReducer**
41
+ A custom reducer function that takes an `initialState` and an object of actions, returning a new state based on the action type.
42
+
43
+ ```ts
44
+ const reducer = useAdvReducer(initialState, {
45
+ increment: (state) => ({ count: state.count + 1 }),
46
+ });
47
+ const [state, dispatch] = useReducer(reducer, initialState);
48
+ ```
49
+
50
+ ---
51
+
52
+ 📌 **useFetch**
53
+ Fetches data from a given URL and manages the loading, error, and data states.
54
+
55
+ ```ts
56
+ const { data, loading, error } = useFetch<User[]>('/api/users');
57
+ ```
58
+
59
+ ---
60
+
61
+ 📌 **useLocalStorage**
62
+ A hook to persist state in `localStorage`. It initializes state from `localStorage` and updates it whenever the value changes.
63
+
64
+ ```ts
65
+ const [token, setToken] = useLocalStorage('authToken', '');
66
+ ```
67
+
68
+ ---
69
+
70
+ 📌 **useToggle**
71
+ A simple boolean toggle hook that returns a state and a function to toggle its value.
72
+
73
+ ```ts
74
+ const [isOpen, toggle] = useToggle(false);
75
+ ```
76
+
77
+ ---
78
+
79
+ 📌 **useDebounce**
80
+ Delays updating the state until after a specified delay, useful for preventing frequent updates (e.g., handling user input).
12
81
 
13
- - **`useAxios`**: A custom hook for making API requests using Axios. It manages request states (`loading`, `error`, `data`) and provides a function (`makeRequest`) to initiate a request.
82
+ ```ts
83
+ const debouncedSearch = useDebounce(searchText, 500);
84
+ ```
14
85
 
15
- - **`useAdvReducer`**: A custom reducer function that takes an `initialState` and an object of actions, returning a new state based on the action type.
86
+ ---
16
87
 
17
- - **`useFetch`**: Fetches data from a given URL and manages the loading, error, and data states.
88
+ 📌 **useThrottle**
89
+ Limits how often a value updates within a given time interval, useful for performance optimization.
18
90
 
19
- - **`useLocalStorage`**: A hook to persist state in `localStorage`. It initializes state from `localStorage` and updates it whenever the value changes.
91
+ ```ts
92
+ const throttledScroll = useThrottle(scrollValue, 300);
93
+ ```
20
94
 
21
- - **`useToggle`**: A simple boolean toggle hook that returns a state and a function to toggle its value.
95
+ ---
22
96
 
23
- - **`useDebounce`**: Delays updating the state until after a specified delay, useful for preventing frequent updates (e.g., handling user input).
97
+ 📌 **usePrevious**
98
+ Returns the previous value of a state or prop.
24
99
 
25
- - **`useThrottle`**: Limits how often a value updates within a given time interval, useful for performance optimization.
100
+ ```ts
101
+ const prevValue = usePrevious(currentValue);
102
+ ```
26
103
 
27
- - **`usePrevious`**: Keeps track of the previous value of a state or prop.
104
+ ---
28
105
 
29
- - **`useMediaQuery`**: Checks if a media query matches the current viewport size and updates the state accordingly.
106
+ 📌 **useMediaQuery**
107
+ Checks if a media query matches the current viewport size and updates the state accordingly.
30
108
 
31
- - **`useClipboard`**: Copies text to the clipboard and provides a state to indicate if copying was successful.
109
+ ```ts
110
+ const isMobile = useMediaQuery('(max-width: 768px)');
111
+ ```
112
+
113
+ ---
114
+
115
+ 📌 **useClipboard**
116
+ Copies text to the clipboard and provides a state to indicate if copying was successful.
117
+
118
+ ```ts
119
+ const [copied, copyToClipboard] = useClipboard();
120
+ copyToClipboard('Text to copy');
121
+ ```
32
122
 
33
- - **`useInterval`**: Runs a callback function at a specified time interval and clears it when the delay is null or the component unmounts.
123
+ ---
34
124
 
35
- - **`useWindowSize`**: Tracks the width and height of the browser window and updates when resized.
125
+ 📌 **useInterval**
126
+ Runs a callback function at a specified time interval and clears it when the delay is null or the component unmounts.
36
127
 
37
- - **`useKeyPress`**: Detects whether a specific key is being pressed or released.
128
+ ```ts
129
+ useInterval(() => {
130
+ console.log('Tick');
131
+ }, 1000);
132
+ ```
38
133
 
39
- - **`useOnlineStatus`**: Monitors the user's network connection status (online/offline).
134
+ ---
40
135
 
41
- - **`useScrollPosition`**: Tracks the horizontal (x) and vertical (y) scroll positions of the window.
136
+ 📌 **useWindowSize**
137
+ Tracks the width and height of the browser window and updates when resized.
42
138
 
43
- - **`useTimeout`**: Executes a function after a specified delay and cleans up automatically when dependencies change.
139
+ ```ts
140
+ const { width, height } = useWindowSize();
141
+ ```
44
142
 
45
- - **`useDarkMode`**: Detects and toggles dark mode based on the user's system preference.
143
+ ---
46
144
 
47
- - **`useForm`**: Manages form state, handles input changes, and performs validation using provided validators.
145
+ 📌 **useKeyPress**
146
+ Detects whether a specific key is being pressed or released.
48
147
 
49
- - **`useArray<T>`**: Provides an array state with helper functions to manipulate it, including setting, adding, removing by index, and clearing elements.
148
+ ```ts
149
+ const isEnterPressed = useKeyPress('Enter');
150
+ ```
50
151
 
51
- - **`useStepper`**: Manages step-based navigation by keeping track of the current step index and providing functions to move forward, backward, and reset.
152
+ ---
52
153
 
53
- - **`useTimeoutFn`**: Executes a callback function after a specified delay and provides functions to reset or clear the timeout.
154
+ 📌 **useOnlineStatus**
155
+ Monitors the user's network connection status (online/offline).
54
156
 
55
- - **`useDebouncedCallback`**: Delays the execution of a callback function until after a specified delay, resetting the delay on each call to prevent frequent execution.
157
+ ```ts
158
+ const isOnline = useOnlineStatus();
159
+ ```
56
160
 
57
- - **`useScrollLock`**: Locks or unlocks scrolling on the webpage when the `lock` parameter changes.
161
+ ---
58
162
 
59
- - **`useResizeObserver<T>`**: Observes and returns the dimensions of an HTML element using the `ResizeObserver` API.
163
+ 📌 **useScrollPosition**
164
+ Tracks the horizontal (x) and vertical (y) scroll positions of the window.
60
165
 
61
- - **`useMousePosition`**: Tracks the user's mouse position in real-time and returns the coordinates.
166
+ ```ts
167
+ const { x, y } = useScrollPosition();
168
+ ```
62
169
 
63
- - **`useScrollDirection`**: Determines whether the user is scrolling up or down based on window scroll position changes.
170
+ ---
64
171
 
65
- - **`useImageLoader`**: Loads an image and provides `loaded` and `error` states to track its loading status.
172
+ 📌 **useTimeout**
173
+ Executes a function after a specified delay and cleans up automatically when dependencies change.
66
174
 
67
- - **`usePersistedState<T>`**: Stores and retrieves state from `localStorage` to persist data across page reloads.
175
+ ```ts
176
+ useTimeout(() => {
177
+ console.log('Time\'s up!');
178
+ }, 2000);
179
+ ```
68
180
 
69
- - **`useReducedMotion`**: Detects if the user has enabled the "Reduce Motion" accessibility setting in their system preferences.
181
+ ---
70
182
 
71
- - **`useCookie`**: Manages cookies by providing functions to get, set, and delete a specific cookie by its key.
183
+ 📌 **useDarkMode**
184
+ Detects and toggles dark mode based on the user's system preference.
72
185
 
73
- - **`useFetchRetry`**: Performs an HTTP request with retry logic, retrying a specified number of times upon failure before returning an error.
186
+ ```ts
187
+ const [isDarkMode, toggleDarkMode] = useDarkMode();
188
+ ```
74
189
 
75
- - **`useDelay`**: Delays the update of a value for a specified amount of time before reflecting it in the state.
190
+ ---
76
191
 
77
- - **`useVisibilityChange`**: Tracks the visibility state of the document and returns whether the page is currently visible or hidden.
192
+ 📌 **useForm**
193
+ Manages form state, handles input changes, and performs validation using provided validators.
78
194
 
79
- - **`useDebouncedValue`**: Debounces a value to avoid immediate changes, returning the delayed value after a specified delay.
195
+ ```ts
196
+ const { values, errors, handleChange, validate } = useForm({ name: '', email: '' });
80
197
 
81
- - **`useAsync`**: Handles the state of an asynchronous function, including loading, success, and error states, with the ability to trigger the execution of the async operation.
198
+ handleChange('name', 'John');
82
199
 
83
- - **`useScript`**: Dynamically loads an external script, managing its loading, ready, and error states, and optionally removes the script on unmount.
200
+ validate({
201
+ name: (val) => (!val ? 'Required' : null),
202
+ email: (val) => (!val.includes('@') ? 'Invalid email' : null),
203
+ });
204
+ ```
84
205
 
85
- - **`useReducedMotion`**: Detects if the user has enabled the "Reduce Motion" accessibility setting and returns a boolean indicating whether reduced motion is preferred.
206
+ ---
86
207
 
87
- - **`useIndexedDB`**: Fetches data from an IndexedDB store, handling errors and updating the state with the fetched data.
208
+ 📌 **useArray**
209
+ Provides an array state with helper functions to manipulate it, including setting, adding, removing by index, and clearing elements.
88
210
 
89
- - **`useGeoLocation`**: Retrieves the user's current geographic location and returns it along with any error encountered.
211
+ ```ts
212
+ const { array, set, push, removeByIndex, clear } = useArray([1, 2, 3]);
90
213
 
91
- - **`useTimer`**: Starts a countdown timer that updates the time every second, returning the current time and any errors.
214
+ push(4); // [1, 2, 3, 4]
215
+ removeByIndex(1); // ➝ [1, 3, 4]
216
+ clear(); // ➝ []
217
+ ```
92
218
 
93
- - **`useIsMounted`**: Tracks whether the component is mounted or unmounted, returning a boolean value indicating the component's mount status.
219
+ ---
94
220
 
95
- - **`useCss`**: Dynamically applies custom CSS to the document and removes it when the component unmounts, handling any errors during the process.
221
+ 📌 **useStepper**
222
+ Manages step-based navigation by keeping track of the current step index and providing functions to move forward, backward, and reset.
96
223
 
97
- - **`useSpeak`**: Converts text to speech using the Web Speech API, allowing the text to be spoken and handling errors.
224
+ ```ts
225
+ const { activeStep, handleNext, handleBack, handleReset, isFirstStep, isLastStep } = useStepper(5);
98
226
 
99
- - **`useCountUp`**: Animates a counter that counts up from 0 to a target value within a specified duration, returning the current count and any errors.
227
+ handleNext(); // advances step
228
+ handleBack(); // ➝ goes back
229
+ handleReset(); // ➝ step 0
230
+ ```
100
231
 
101
- - **`useCountDown`**: Counts down from a specified start value to zero, updating every second and returning the current count and any errors.
232
+ ---
102
233
 
103
- - **`useBattery`**: Monitors the battery status of the device, including level, charging status, and remaining charging or discharging time.
234
+ 📌 **useTimeoutFn**
235
+ Executes a callback function after a specified delay and provides functions to reset or clear the timeout.
104
236
 
105
- - **`useEventListener`**: Listens for a specified event on an element or window, and triggers the handler function when the event is fired. It ensures proper cleanup when the component is unmounted.
237
+ ```ts
238
+ const { reset, clear } = useTimeoutFn(() => doSomething(), 1000);
106
239
 
107
- - **`useHistory`**: Provides methods to navigate the browser history, including pushing and replacing history states, as well as moving back and forward in the history stack.
240
+ reset(); // restarts timeout
241
+ clear(); // ➝ clears timeout
242
+ ```
108
243
 
109
- - **`usePreferredLanguage`**: Retrieves the user's preferred language and languages from the browser, and checks if the browser supports the language APIs.
244
+ ---
110
245
 
111
- - **`useSessionStorage`**: Stores and retrieves data from the `sessionStorage` API, persisting the data during the session. It provides a getter and setter for session-based data.
246
+ 📌 **useDebouncedCallback**
247
+ Delays the execution of a callback function until after a specified delay, resetting the delay on each call to prevent frequent execution.
112
248
 
113
- - **`useSound`**: Controls the playback of an audio file, including play, pause, and stop functionalities, while also managing the audio volume and handling any errors.
249
+ ```ts
250
+ const debounced = useDebouncedCallback(() => search(input), 300);
114
251
 
115
- - **`useTouch`**: Tracks touch events on a given DOM element, returning the touch positions for `touchstart`, `touchmove`, and `touchend`.
252
+ input.onChange = debounced;
253
+ ```
254
+
255
+ ---
256
+
257
+ 📌 **useScrollLock**
258
+ Locks or unlocks scrolling on the webpage when the `lock` parameter changes.
259
+
260
+ ```ts
261
+ useScrollLock(true); // ➝ disables body scroll
262
+ ```
263
+
264
+ ---
265
+
266
+ 📌 **useResizeObserver**
267
+ Observes and returns the dimensions of an HTML element using the `ResizeObserver` API.
268
+
269
+ ```ts
270
+ const size = useResizeObserver(ref);
271
+
272
+ // size = { width: 200, height: 100 }
273
+ ```
274
+
275
+ ---
276
+
277
+ 📌 **useMousePosition**
278
+ Tracks the user's mouse position in real-time and returns the coordinates.
279
+
280
+ ```ts
281
+ const { x, y } = useMousePosition();
282
+ ```
283
+
284
+ ---
285
+
286
+ 📌 **useScrollDirection**
287
+ Determines whether the user is scrolling up or down based on window scroll position changes.
288
+
289
+ ```ts
290
+ const direction = useScrollDirection(); // ➝ 'up' | 'down'
291
+ ```
292
+
293
+ ---
294
+
295
+ 📌 **useImageLoader**
296
+ Loads an image and provides `loaded` and `error` states to track its loading status.
297
+
298
+ ```ts
299
+ const { loaded, error } = useImageLoader('/logo.png');
300
+ ```
301
+
302
+ ---
303
+
304
+ 📌 **usePersistedState**
305
+ Stores and retrieves state from `localStorage` to persist data across page reloads.
306
+
307
+ ```ts
308
+ const [theme, setTheme] = usePersistedState('theme', 'light');
309
+ ```
310
+
311
+ ---
312
+
313
+ 📌 **useReducedMotion**
314
+ Detects if the user has enabled the "Reduce Motion" accessibility setting in their system preferences.
315
+
316
+ ```ts
317
+ const prefersReduced = useReducedMotion(); // ➝ true | false
318
+ ```
319
+
320
+ ---
321
+
322
+ 📌 **useCookie**
323
+ Manages cookies by providing functions to get, set, and delete a specific cookie by its key.
324
+
325
+ ```ts
326
+ const [token, setToken, deleteToken] = useCookie('token');
327
+
328
+ setToken('abc123');
329
+ deleteToken();
330
+ ```
331
+
332
+ ---
333
+
334
+ 📌 **useFetchRetry**
335
+ Performs an HTTP request with retry logic, retrying a specified number of times upon failure before returning an error.
336
+
337
+ ```ts
338
+ const { data, loading, error } = useFetchRetry('/api/user', { method: 'GET' }, 3);
339
+ ```
340
+
341
+ ---
342
+
343
+ 📌 **useDelay**
344
+ Delays the update of a value for a specified amount of time before reflecting it in the state.
345
+
346
+ ```ts
347
+ const delayedValue = useDelay(value, 500);
348
+ ```
349
+
350
+ ---
351
+
352
+ 📌 **useVisibilityChange**
353
+ Tracks the visibility state of the document and returns whether the page is currently visible or hidden.
354
+
355
+ ```ts
356
+ const isVisible = useVisibilityChange(); // ➝ true | false
357
+ ```
358
+
359
+ ---
360
+
361
+ 📌 **useDebouncedValue**
362
+ Debounces a value to avoid immediate changes, returning the delayed value after a specified delay.
363
+
364
+ ```ts
365
+ const debouncedSearch = useDebouncedValue(input, 300);
366
+ ```
367
+
368
+ ---
369
+
370
+ 📌 **useAsync**
371
+ Handles the state of an asynchronous function, including loading, success, and error states, with the ability to trigger the execution of the async operation.
372
+
373
+ ```ts
374
+ const { execute, status, value, error } = useAsync(fetchUser);
375
+
376
+ execute(); // ➝ runs the async function
377
+ ```
378
+
379
+ ---
380
+
381
+ 📌 **useScript**
382
+ Dynamically loads an external script, managing its loading, ready, and error states, and optionally removes the script on unmount.
383
+
384
+ ```ts
385
+ const status = useScript('https://js.stripe.com/v3');
386
+
387
+ // status ➝ 'loading' | 'ready' | 'error'
388
+ ```
389
+
390
+ ---
391
+
392
+ 📌 **useIndexedDB**
393
+ Fetches data from an IndexedDB store, handling errors and updating the state with the fetched data.
394
+
395
+ ```ts
396
+ const { data, error } = useIndexedDB<MyType>('myDB', 'myStore');
397
+ ```
398
+
399
+ ---
400
+
401
+ 📌 **useGeoLocation**
402
+ Retrieves the user's current geographic location and returns it along with any error encountered.
403
+
404
+ ```ts
405
+ const { position, error } = useGeoLocation();
406
+ ```
407
+
408
+ ---
409
+
410
+ 📌 **useTimer**
411
+ Starts a countdown timer that updates the time every second, returning the current time and any errors.
412
+
413
+ ```ts
414
+ const { time, error } = useTimer(60); // starts from 60 and counts down
415
+ ```
416
+
417
+ ---
418
+
419
+ 📌 **useIsMounted**
420
+ Tracks whether the component is mounted or unmounted, returning a boolean value indicating the component's mount status.
421
+
422
+ ```ts
423
+ const isMounted = useIsMounted();
424
+ ```
425
+
426
+ ---
427
+
428
+ 📌 **useCss**
429
+ Dynamically applies custom CSS to the document and removes it when the component unmounts, handling any errors during the process.
430
+
431
+ ```ts
432
+ const { error } = useCss('body { background: #f5f5f5; }');
433
+ ```
434
+
435
+ ---
436
+
437
+ 📌 **useSpeak**
438
+ Converts text to speech using the Web Speech API, allowing the text to be spoken and handling errors.
439
+ ```ts
440
+ const { speak, error } = useSpeak('Hello world!');
441
+ speak();
442
+ ```
443
+
444
+ ---
445
+
446
+ 📌 **useCountUp**
447
+ Animates a counter that counts up from 0 to a target value within a specified duration, returning the current count and any errors.
448
+
449
+ ```ts
450
+ const { count, error } = useCountUp(100, 5000); // counts up to 100 in 5s
451
+ ```
452
+
453
+ ---
454
+
455
+ 📌 **useCountDown**
456
+ Counts down from a specified start value to zero, updating every second and returning the current count and any errors.
457
+
458
+ ```ts
459
+ const { count, error } = useCountDown(10); // counts down from 10
460
+ ```
461
+
462
+ ---
463
+
464
+ 📌 **useBattery**
465
+ Monitors the battery status of the device, including level, charging status, and remaining charging or discharging time.
466
+
467
+ ```ts
468
+ const { level, charging, supported, loading, chargingTime, dischargingTime } = useBattery();
469
+ ```
470
+
471
+ ---
472
+
473
+ 📌 **useEventListener**
474
+ Listens for a specified event on an element or window, and triggers the handler function when the event is fired. It ensures proper cleanup when the component is unmounted.
475
+
476
+ ```ts
477
+ useEventListener('resize', (e) => {
478
+ console.log('Window resized');
479
+ });
480
+ ```
481
+
482
+ ---
483
+
484
+ 📌 **useHistory**
485
+ Provides methods to navigate the browser history, including pushing and replacing history states, as well as moving back and forward in the history stack.
486
+
487
+ ```ts
488
+ const {
489
+ history,
490
+ state,
491
+ push,
492
+ replace,
493
+ goBack,
494
+ goForward
495
+ } = useHistory();
496
+
497
+ push('/about', { from: 'home' });
498
+ replace('/profile');
499
+ goBack();
500
+ goForward();
501
+ ```
502
+
503
+ ---
504
+
505
+ 📌 **usePreferredLanguage**
506
+ Retrieves the user's preferred language and languages from the browser, and checks if the browser supports the language APIs.
507
+
508
+ ```ts
509
+ const {
510
+ language,
511
+ languages,
512
+ isSupported
513
+ } = usePreferredLanguage();
514
+
515
+ console.log(language); // e.g., "en-US"
516
+ ```
517
+
518
+ ---
519
+
520
+ 📌 **useSessionStorage**
521
+ Stores and retrieves data from the `sessionStorage` API, persisting the data during the session. It provides a getter and setter for session-based data.
522
+
523
+ ```ts
524
+ const [value, setValue] = useSessionStorage("myKey", "default");
525
+
526
+ setValue("newValue");
527
+ console.log(value);
528
+ ```
529
+
530
+ ---
531
+
532
+ 📌 **useSound**
533
+ Controls the playback of an audio file, including play, pause, and stop functionalities, while also managing the audio volume and handling any errors.
534
+
535
+ ```ts
536
+ const {
537
+ play,
538
+ pause,
539
+ stop,
540
+ setVolume,
541
+ isPlaying,
542
+ error
543
+ } = useSound("/sound.mp3");
544
+
545
+ play();
546
+ pause();
547
+ stop();
548
+ setVolume(0.5);
549
+ ```
550
+
551
+ ---
552
+
553
+ 📌 **useTouch**
554
+ Tracks touch events on a given DOM element, returning the touch positions for `touchstart`, `touchmove`, and `touchend`.
555
+
556
+ ```ts
557
+ const ref = useRef(null);
558
+ const {
559
+ touchStart,
560
+ touchMove,
561
+ touchEnd
562
+ } = useTouch(ref);
563
+
564
+ <div ref={ref}>Swipe here</div>
565
+ ```
566
+
567
+ ---
568
+
569
+ 📌 **useUpdateEffect**
570
+ Executes a side effect on updates after the initial render, skipping the effect during the first render to avoid unnecessary executions.
571
+
572
+ ```ts
573
+ useUpdateEffect(() => {
574
+ console.log("This runs only on updates.");
575
+ }, [value]);
576
+ ```
577
+
578
+ **COMPONENTS** -------------------------------------------------------------------------------------------
579
+ ✅ **DynamicLoader**
580
+ A Higher-Order Component (HOC) that dynamically loads a React component using `React.lazy()` with `Suspense`, while wrapping it in an `ErrorBoundary` to handle potential errors gracefully. It ensures that the component is loaded only when needed, reducing the initial bundle size and improving performance.
581
+
582
+ ```jsx
583
+ import React, { lazy } from "react";
584
+ const MyComponent = DynamicLoader(lazy(() => import("./MyComponent")));
585
+
586
+ ```
587
+ ✅ **AlertMessage**
588
+ A functional React component that displays dynamic alerts using the enqueueSnackbar function. It provides a customizable message with a specified type and duration. The alerts can be dismissed manually by clicking a close button, and they support various configurations such as position, auto-hide duration, and duplicate prevention.
589
+
590
+ ```jsx
591
+ <AlertMessage type="success" msg="Data saved successfully!" />
592
+ ```
116
593
 
117
- - **`useUpdateEffect`**: Executes a side effect on updates after the initial render, skipping the effect during the first render to avoid unnecessary executions.
594
+ ✏️ **Authors**
118
595
 
119
- - **`DynamicLoader`**: A Higher-Order Component (HOC) that dynamically loads a React component using `React.lazy()` with `Suspense`, while wrapping it in an `ErrorBoundary` to handle potential errors gracefully. It ensures that the component is loaded only when needed, reducing the initial bundle size and improving performance.
596
+ ![NPM](https://img.shields.io/badge/Author-React%20Expert-red) &nbsp; ![npm](https://img.shields.io/npm/v/react-hook-toolkit?color=1C939D) &nbsp; ![npm](https://img.shields.io/npm/dt/react-hook-toolkit) &nbsp; ![NPM](https://img.shields.io/npm/l/react-hook-toolkit) &nbsp; ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/react-hook-toolkit)
120
597
 
121
- ## License
598
+ **License**
122
599
 
123
600
  [MIT](https://opensource.org/licenses)
@@ -5,5 +5,5 @@ interface PropsType {
5
5
  msg: string;
6
6
  duration?: number;
7
7
  }
8
- declare const AlertMessage: FC<PropsType>;
8
+ export declare const AlertMessage: FC<PropsType>;
9
9
  export default AlertMessage;
@@ -52,7 +52,7 @@ var LoadingScreen = function () {
52
52
  };
53
53
  // prettier-ignore
54
54
  export var DynamicLoader = function (Component) { return function (props) { return (_jsx(Error, { children: _jsx(Suspense, { fallback: _jsx(LoadingScreen, {}), children: _jsx(Component, __assign({}, props)) }) })); }; };
55
- var AlertMessage = function (_a) {
55
+ export var AlertMessage = function (_a) {
56
56
  var type = _a.type, msg = _a.msg, duration = _a.duration;
57
57
  var _b = getHook('snackBar'), enqueueSnackbar = _b.enqueueSnackbar, closeSnackbar = _b.closeSnackbar;
58
58
  if (msg !== undefined && msg !== '') {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import 'nprogress/nprogress.css';
2
2
  import { ReactHooksWrapper, getHook, setHook } from "./hookExecuter/hookExecuter";
3
- import { DynamicLoader } from './hooks/hooksComp';
3
+ import { DynamicLoader, AlertMessage } from './hooks/hooksComp';
4
4
  import { useAxios, useAdvReducer, useFetch, useLocalStorage, useToggle, useDebounce, useThrottle, usePrevious, useMediaQuery, useClipboard, useInterval, useWindowSize, useKeyPress, useOnlineStatus, useScrollPosition, useTimeout, useDarkMode, useForm, useArray, useStepper, useUpdateEffect, useTouch, useSound, useSessionStorage, usePreferredLanguage, useHistory, useEventListener, useBattery, useDebouncedCallback, useScrollLock, useResizeObserver, useMousePosition, useScrollDirection, useImageLoader, usePersistedState, useReducedMotion, useCookie, useFetchRetry, useDelay, useVisibilityChange, useDebouncedValue, useAsync, useScript, useIndexedDB, useGeoLocation, useTimer, useIsMounted, useCss, useSpeak, useCountUp, useCountDown } from './hooks/hooks';
5
5
  export default ReactHooksWrapper;
6
- export { getHook, setHook, useAxios, useAdvReducer, useFetch, useLocalStorage, useToggle, useDebounce, useThrottle, usePrevious, useMediaQuery, useClipboard, useInterval, useWindowSize, useKeyPress, useOnlineStatus, useScrollPosition, useTimeout, useDarkMode, useForm, useArray, useStepper, useUpdateEffect, useTouch, useSound, useSessionStorage, usePreferredLanguage, useHistory, useEventListener, useBattery, useDebouncedCallback, useScrollLock, useResizeObserver, useMousePosition, useScrollDirection, useImageLoader, usePersistedState, useReducedMotion, useCookie, useFetchRetry, useDelay, useVisibilityChange, useDebouncedValue, useAsync, useScript, useIndexedDB, useGeoLocation, useTimer, useIsMounted, useCss, useSpeak, useCountUp, useCountDown, DynamicLoader };
6
+ export { getHook, setHook, useAxios, useAdvReducer, useFetch, useLocalStorage, useToggle, useDebounce, useThrottle, usePrevious, useMediaQuery, useClipboard, useInterval, useWindowSize, useKeyPress, useOnlineStatus, useScrollPosition, useTimeout, useDarkMode, useForm, useArray, useStepper, useUpdateEffect, useTouch, useSound, useSessionStorage, usePreferredLanguage, useHistory, useEventListener, useBattery, useDebouncedCallback, useScrollLock, useResizeObserver, useMousePosition, useScrollDirection, useImageLoader, usePersistedState, useReducedMotion, useCookie, useFetchRetry, useDelay, useVisibilityChange, useDebouncedValue, useAsync, useScript, useIndexedDB, useGeoLocation, useTimer, useIsMounted, useCss, useSpeak, useCountUp, useCountDown, DynamicLoader, AlertMessage };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import 'nprogress/nprogress.css';
2
2
  import { ReactHooksWrapper, getHook, setHook } from "./hookExecuter/hookExecuter";
3
- import { DynamicLoader } from './hooks/hooksComp';
3
+ import { DynamicLoader, AlertMessage } from './hooks/hooksComp';
4
4
  import { useAxios, useAdvReducer, useFetch, useLocalStorage, useToggle, useDebounce, useThrottle, usePrevious, useMediaQuery, useClipboard, useInterval, useWindowSize, useKeyPress, useOnlineStatus, useScrollPosition, useTimeout, useDarkMode, useForm, useArray, useStepper, useUpdateEffect, useTouch, useSound, useSessionStorage, usePreferredLanguage, useHistory, useEventListener, useBattery, useDebouncedCallback, useScrollLock, useResizeObserver, useMousePosition, useScrollDirection, useImageLoader, usePersistedState, useReducedMotion, useCookie, useFetchRetry, useDelay, useVisibilityChange, useDebouncedValue, useAsync, useScript, useIndexedDB, useGeoLocation, useTimer, useIsMounted, useCss, useSpeak, useCountUp, useCountDown, } from './hooks/hooks';
5
5
  export default ReactHooksWrapper;
6
- export { getHook, setHook, useAxios, useAdvReducer, useFetch, useLocalStorage, useToggle, useDebounce, useThrottle, usePrevious, useMediaQuery, useClipboard, useInterval, useWindowSize, useKeyPress, useOnlineStatus, useScrollPosition, useTimeout, useDarkMode, useForm, useArray, useStepper, useUpdateEffect, useTouch, useSound, useSessionStorage, usePreferredLanguage, useHistory, useEventListener, useBattery, useDebouncedCallback, useScrollLock, useResizeObserver, useMousePosition, useScrollDirection, useImageLoader, usePersistedState, useReducedMotion, useCookie, useFetchRetry, useDelay, useVisibilityChange, useDebouncedValue, useAsync, useScript, useIndexedDB, useGeoLocation, useTimer, useIsMounted, useCss, useSpeak, useCountUp, useCountDown, DynamicLoader };
6
+ export { getHook, setHook, useAxios, useAdvReducer, useFetch, useLocalStorage, useToggle, useDebounce, useThrottle, usePrevious, useMediaQuery, useClipboard, useInterval, useWindowSize, useKeyPress, useOnlineStatus, useScrollPosition, useTimeout, useDarkMode, useForm, useArray, useStepper, useUpdateEffect, useTouch, useSound, useSessionStorage, usePreferredLanguage, useHistory, useEventListener, useBattery, useDebouncedCallback, useScrollLock, useResizeObserver, useMousePosition, useScrollDirection, useImageLoader, usePersistedState, useReducedMotion, useCookie, useFetchRetry, useDelay, useVisibilityChange, useDebouncedValue, useAsync, useScript, useIndexedDB, useGeoLocation, useTimer, useIsMounted, useCss, useSpeak, useCountUp, useCountDown, DynamicLoader, AlertMessage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hook-toolkit",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Ultimate package for React developers, offering a powerful collection of hooks and components to enhance their development experience.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",