Skip to content

Commit

Permalink
feat: useDebounce 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
sinji2102 committed Nov 25, 2024
1 parent 3e6b279 commit 815a405
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/hooks/useDebounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect, useState } from "react";

const useDebounce = (value: string, delay: number) => {
const [debouncedValue, setDebouncedValue] = useState(value);

useEffect(() => {
const timer = setTimeout(() => {
setDebouncedValue(value);
}, delay);

return () => {
clearTimeout(timer);
};
}, [value]);

return debouncedValue;
};

export default useDebounce;

0 comments on commit 815a405

Please sign in to comment.