react-hook-toolkit 1.0.17 → 1.0.18

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
@@ -10,14 +10,12 @@ Install the package:
10
10
  ```bash
11
11
  npm install react-hook-toolkit
12
12
  # or
13
- yarn add react-hook-toolkit
14
- # or
15
13
  pnpm add react-hook-toolkit
16
14
  ```
17
15
 
18
16
  ### **Authors**
19
17
 
20
- ![NPM](https://img.shields.io/badge/Author-NPM_Teams-red)   ![npm](https://img.shields.io/npm/v/react-hook-toolkit?color=1C939D)   ![npm](https://img.shields.io/npm/dt/react-hook-toolkit)   ![NPM](https://img.shields.io/npm/l/react-hook-toolkit)   ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/react-hook-toolkit)
18
+ ![NPM](https://img.shields.io/badge/Author-React_Developers-red)   ![npm](https://img.shields.io/npm/v/react-hook-toolkit?color=1C939D)   ![npm](https://img.shields.io/npm/dt/react-hook-toolkit)   ![NPM](https://img.shields.io/npm/l/react-hook-toolkit)   ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/react-hook-toolkit)
21
19
 
22
20
  ### **Browser Support**
23
21
 
@@ -465,6 +463,19 @@ goBack();
465
463
  goForward();
466
464
  ```
467
465
 
466
+ ---
467
+ 📌 **useRecentSearch**
468
+ Return and manage recent searched history.
469
+
470
+ ```ts
471
+ const { recentSearches, addSearch, clearSearch, hasSearch } = useRecentSearch<SearchItem>({
472
+ key: 'myRecentItems',
473
+ limit: 5,
474
+ uniqueKey: 'id',
475
+ excludeEmpty: true,
476
+ });
477
+
478
+ ```
468
479
  ---
469
480
  📌 **useHistoryState**
470
481
  Manages state history with undo/redo capabilities.
@@ -37,4 +37,16 @@ export declare function useLongPress(callback: (event: Event) => void, options?:
37
37
  onTouchStart: any;
38
38
  onTouchEnd: any;
39
39
  };
40
+ type UseRecentSearchOptions = {
41
+ key?: string;
42
+ limit?: number;
43
+ uniqueKey?: string;
44
+ excludeEmpty?: boolean;
45
+ };
46
+ export declare const useRecentSearch: (options?: UseRecentSearchOptions) => {
47
+ recentSearches: any;
48
+ addSearch: (item: any) => void;
49
+ clearSearch: () => void;
50
+ hasSearch: (value: string) => any;
51
+ };
40
52
  export {};
@@ -265,3 +265,45 @@ export function useLongPress(callback, options) {
265
265
  onTouchEnd: cancel,
266
266
  }); }, [start, cancel]);
267
267
  }
268
+ export var useRecentSearch = function (options) {
269
+ if (options === void 0) { options = {}; }
270
+ var _a = options.key, key = _a === void 0 ? 'recentSearches' : _a, _b = options.limit, limit = _b === void 0 ? 3 : _b, _c = options.uniqueKey, uniqueKey = _c === void 0 ? 'index' : _c, _d = options.excludeEmpty, excludeEmpty = _d === void 0 ? true : _d;
271
+ var _e = useState([]), recentSearches = _e[0], setRecentSearches = _e[1];
272
+ useEffect(function () {
273
+ var saved = localStorage.getItem(key);
274
+ if (saved) {
275
+ try {
276
+ var parsed = JSON.parse(saved);
277
+ if (Array.isArray(parsed)) {
278
+ setRecentSearches(parsed.slice(0, limit));
279
+ }
280
+ }
281
+ catch (e) {
282
+ console.error('Failed to parse recent searches', e);
283
+ localStorage.removeItem(key);
284
+ }
285
+ }
286
+ }, [key, limit]);
287
+ var addSearch = useCallback(function (item) {
288
+ if (excludeEmpty && !item[uniqueKey])
289
+ return;
290
+ try {
291
+ setRecentSearches(function (prev) {
292
+ var updated = __spreadArray([item], prev.filter(function (p) { return p[uniqueKey] !== item[uniqueKey]; }), true).slice(0, limit);
293
+ localStorage.setItem(key, JSON.stringify(updated));
294
+ return updated;
295
+ });
296
+ }
297
+ catch (error) {
298
+ console.error('Failed to update recent searches:', error);
299
+ }
300
+ }, [excludeEmpty, uniqueKey, key, limit]);
301
+ var hasSearch = function (value) {
302
+ return recentSearches.some(function (item) { var _a; return ((_a = item[uniqueKey]) === null || _a === void 0 ? void 0 : _a.toString().trim()) === value.trim(); });
303
+ };
304
+ var clearSearch = function () {
305
+ localStorage.removeItem(key);
306
+ setRecentSearches([]);
307
+ };
308
+ return { recentSearches: recentSearches, addSearch: addSearch, clearSearch: clearSearch, hasSearch: hasSearch };
309
+ };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import 'nprogress/nprogress.css';
2
2
  import { ReactHooksWrapper, getHook, setHook } from "./hookExecuter/chunk143";
3
3
  import { DynamicLoader, AlertMessage, FilePreview, LabeledValue, DetailsCard, UploadFile, DownloadFile } from './hooks/chunk613852';
4
4
  import { FileSkeleton, TableSkeleton, PieChartSkeleton, CardSkeleton, LineChartSkeleton, FieldSkeleton } from './skeletons/chunk613555';
5
- import { useHistoryState, useIdle, useIsFirstRender, useList, useLockBodyScroll, useLongPress } from './hooks/chunk726433';
5
+ import { useHistoryState, useIdle, useIsFirstRender, useList, useLockBodyScroll, useLongPress, useRecentSearch } from './hooks/chunk726433';
6
6
  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, usePersistedForm, useCrossFieldValidation, useFieldArray, useFormSubmit, useSmartForm, useUndo, useFormWizard, useWebSocket, useDragReorder, useInfiniteScroll, useEventListeners, createOptimizedContext } from './hooks/chunk940514';
7
7
  export default ReactHooksWrapper;
8
- 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, usePersistedForm, useCrossFieldValidation, useFieldArray, useFormSubmit, useSmartForm, useUndo, useFormWizard, useWebSocket, useDragReorder, useInfiniteScroll, useEventListeners, useHistoryState, useIdle, useIsFirstRender, useList, useLockBodyScroll, useLongPress, createOptimizedContext, DynamicLoader, AlertMessage, FilePreview, FileSkeleton, TableSkeleton, PieChartSkeleton, CardSkeleton, LineChartSkeleton, FieldSkeleton, LabeledValue, DetailsCard, UploadFile, DownloadFile };
8
+ 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, usePersistedForm, useCrossFieldValidation, useFieldArray, useFormSubmit, useSmartForm, useUndo, useFormWizard, useWebSocket, useDragReorder, useInfiniteScroll, useEventListeners, useHistoryState, useIdle, useIsFirstRender, useList, useLockBodyScroll, useLongPress, useRecentSearch, createOptimizedContext, DynamicLoader, AlertMessage, FilePreview, FileSkeleton, TableSkeleton, PieChartSkeleton, CardSkeleton, LineChartSkeleton, FieldSkeleton, LabeledValue, DetailsCard, UploadFile, DownloadFile };
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import 'nprogress/nprogress.css';
2
2
  import { ReactHooksWrapper, getHook, setHook } from "./hookExecuter/chunk143";
3
3
  import { DynamicLoader, AlertMessage, FilePreview, LabeledValue, DetailsCard, UploadFile, DownloadFile } from './hooks/chunk613852';
4
4
  import { FileSkeleton, TableSkeleton, PieChartSkeleton, CardSkeleton, LineChartSkeleton, FieldSkeleton } from './skeletons/chunk613555';
5
- import { useHistoryState, useIdle, useIsFirstRender, useList, useLockBodyScroll, useLongPress } from './hooks/chunk726433';
5
+ import { useHistoryState, useIdle, useIsFirstRender, useList, useLockBodyScroll, useLongPress, useRecentSearch } from './hooks/chunk726433';
6
6
  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, usePersistedForm, useCrossFieldValidation, useFieldArray, useFormSubmit, useSmartForm, useUndo, useFormWizard, useWebSocket, useDragReorder, useInfiniteScroll, useEventListeners, createOptimizedContext } from './hooks/chunk940514';
7
7
  export default ReactHooksWrapper;
8
- 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, usePersistedForm, useCrossFieldValidation, useFieldArray, useFormSubmit, useSmartForm, useUndo, useFormWizard, useWebSocket, useDragReorder, useInfiniteScroll, useEventListeners, useHistoryState, useIdle, useIsFirstRender, useList, useLockBodyScroll, useLongPress, createOptimizedContext, DynamicLoader, AlertMessage, FilePreview, FileSkeleton, TableSkeleton, PieChartSkeleton, CardSkeleton, LineChartSkeleton, FieldSkeleton, LabeledValue, DetailsCard, UploadFile, DownloadFile };
8
+ 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, usePersistedForm, useCrossFieldValidation, useFieldArray, useFormSubmit, useSmartForm, useUndo, useFormWizard, useWebSocket, useDragReorder, useInfiniteScroll, useEventListeners, useHistoryState, useIdle, useIsFirstRender, useList, useLockBodyScroll, useLongPress, useRecentSearch, createOptimizedContext, DynamicLoader, AlertMessage, FilePreview, FileSkeleton, TableSkeleton, PieChartSkeleton, CardSkeleton, LineChartSkeleton, FieldSkeleton, LabeledValue, DetailsCard, UploadFile, DownloadFile };
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare const promise: (time: number) => Promise<unknown>;
2
2
  export declare function throttle<T extends (...args: any[]) => void>(func: T, limit: number): T;
3
+ export declare const debounceUtils: <T extends (...args: any[]) => void>(func: T, delay: number) => (...args: Parameters<T>) => void;
package/dist/utils.js CHANGED
@@ -23,3 +23,14 @@ export function throttle(func, limit) {
23
23
  }
24
24
  };
25
25
  }
26
+ export var debounceUtils = function (func, delay) {
27
+ var timeoutId;
28
+ return function () {
29
+ var args = [];
30
+ for (var _i = 0; _i < arguments.length; _i++) {
31
+ args[_i] = arguments[_i];
32
+ }
33
+ clearTimeout(timeoutId);
34
+ timeoutId = setTimeout(function () { return func.apply(void 0, args); }, delay);
35
+ };
36
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hook-toolkit",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
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",