Skip to content

Commit

Permalink
feat(time): create util hook 'useDebounce' (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
SWARVY committed Aug 17, 2024
1 parent bccc52f commit 7ef2e26
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions apps/time/src/shared/hooks/useDebounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect, useState } from 'react';

interface UseDebounceParams {
value: unknown;
delay: number;
}

export default function useDebounce({ value, delay }: UseDebounceParams) {
const [debouncedValue, setDebouncedValue] = useState<unknown>(value);

useEffect(() => {
const delayDebounceTimer = setTimeout(() => {
setDebouncedValue(value);
}, delay);
return () => clearTimeout(delayDebounceTimer);
}, [value, delay]);

return debouncedValue;
}

0 comments on commit 7ef2e26

Please sign in to comment.