@sohanemon/utils 3.0.4 → 3.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.
@@ -4,6 +4,7 @@ export declare function useMediaQuery(tailwindBreakpoint: 'sm' | 'md' | 'lg' | '
4
4
  export declare const useSwiperRef: () => any[];
5
5
  export declare function useEffectOnce(effect: EffectCallback): void;
6
6
  export declare function useUpdateEffect(effect: EffectCallback, deps: any[]): void;
7
+ export declare function useDebounce<T>(state: T, delay?: number): T;
7
8
  export declare const useIsomorphicEffect: any;
8
9
  export declare function useTimeout(callback: () => void, delay?: number | null): void;
9
10
  export declare function useWindowEvent<K extends string = keyof WindowEventMap>(type: K, listener: K extends keyof WindowEventMap ? (this: Window, ev: WindowEventMap[K]) => void : (this: Window, ev: CustomEvent) => void, options?: boolean | AddEventListenerOptions): void;
@@ -94,6 +94,16 @@ export function useUpdateEffect(effect, deps) {
94
94
  // eslint-disable-next-line react-hooks/exhaustive-deps
95
95
  }, deps);
96
96
  }
97
+ export function useDebounce(state, delay = 500) {
98
+ const [debouncedState, setDebouncedState] = useState(state);
99
+ useEffect(() => {
100
+ const timer = setTimeout(() => setDebouncedState(state), delay);
101
+ return () => {
102
+ clearTimeout(timer);
103
+ };
104
+ }, [state, delay]);
105
+ return debouncedState;
106
+ }
97
107
  export const useIsomorphicEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
98
108
  export function useTimeout(callback, delay = 1000) {
99
109
  const savedCallback = useRef(callback);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sohanemon/utils",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",