aboutsummaryrefslogtreecommitdiff
path: root/src/console/hooks/useDebounce.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2022-05-08 13:33:46 +0000
committerGitHub <noreply@github.com>2022-05-08 13:33:46 +0000
commit9279fff1351406a1f6c37c074cc1997e6a9e97e3 (patch)
treecc8e53f783efc5eb737af31bb9dd15c9e6474782 /src/console/hooks/useDebounce.ts
parent4468afca7a8c9893f71f7e042b25f6c46ba49678 (diff)
parent2a6d6b0967c6f6e269c3eedf4bd6002aee26b9da (diff)
Merge pull request #1418 from ueokande/await-completions
Await fetching completions done completely
Diffstat (limited to 'src/console/hooks/useDebounce.ts')
-rw-r--r--src/console/hooks/useDebounce.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/console/hooks/useDebounce.ts b/src/console/hooks/useDebounce.ts
new file mode 100644
index 0000000..838ff34
--- /dev/null
+++ b/src/console/hooks/useDebounce.ts
@@ -0,0 +1,19 @@
+import React from "react";
+
+const useDebounce = <T extends unknown>(value: T, delay: number) => {
+ const [debouncedValue, setDebouncedValue] = React.useState(value);
+
+ React.useEffect(() => {
+ const timer = setTimeout(() => {
+ setDebouncedValue(value);
+ }, delay);
+
+ return () => {
+ clearTimeout(timer);
+ };
+ }, [value, delay]);
+
+ return debouncedValue;
+};
+
+export default useDebounce;