react-hook-toolkit 1.0.3 → 1.0.4

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