diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2022-05-08 13:33:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-08 13:33:46 +0000 |
commit | 9279fff1351406a1f6c37c074cc1997e6a9e97e3 (patch) | |
tree | cc8e53f783efc5eb737af31bb9dd15c9e6474782 /src/console/hooks | |
parent | 4468afca7a8c9893f71f7e042b25f6c46ba49678 (diff) | |
parent | 2a6d6b0967c6f6e269c3eedf4bd6002aee26b9da (diff) |
Merge pull request #1418 from ueokande/await-completions
Await fetching completions done completely
Diffstat (limited to 'src/console/hooks')
-rw-r--r-- | src/console/hooks/useDebounce.ts | 19 |
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; |