Skip to content

Commit

Permalink
[@mantine/hooks] use-debounced-state: Fix incorrect type definition (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianghita24 authored Feb 1, 2024
1 parent 8b3bf17 commit d78bf86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ describe('use-debounced-state', () => {
act(() => timeoutCallback());
expect(hook.result.current[0]).toEqual('test3');

act(() => hook.result.current[1]((prev) => `${prev}0`));
expect(hook.result.current[0]).toEqual('test3');

act(() => timeoutCallback());
expect(hook.result.current[0]).toEqual('test30');

clearTimeout.mockReset();
expect(clearTimeout).toHaveBeenCalledTimes(0);
act(() => hook.unmount());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { SetStateAction, useCallback, useEffect, useRef, useState } from 'react';

export function useDebouncedState<T = any>(
defaultValue: T,
Expand All @@ -13,7 +13,7 @@ export function useDebouncedState<T = any>(
useEffect(() => clearTimeout, []);

const debouncedSetValue = useCallback(
(newValue: T) => {
(newValue: SetStateAction<T>) => {
clearTimeout();
if (leadingRef.current && options.leading) {
setValue(newValue);
Expand Down

0 comments on commit d78bf86

Please sign in to comment.