diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2022-03-14 13:24:01 +0000 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2022-05-05 07:27:44 +0000 |
commit | bc890c55bfbd6d1aa4ece5b0ef96a9ab6d358ad7 (patch) | |
tree | 4b268cfb3040ee9b32c7d22d5e8fd47fac3d46bb /src/console/completion/hooks | |
parent | 823bad63384de90c11653f0afa253cc5d0e19239 (diff) |
Get completion types on component initialization
Diffstat (limited to 'src/console/completion/hooks')
-rw-r--r-- | src/console/completion/hooks/clients.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/console/completion/hooks/clients.ts b/src/console/completion/hooks/clients.ts new file mode 100644 index 0000000..49deb0c --- /dev/null +++ b/src/console/completion/hooks/clients.ts @@ -0,0 +1,23 @@ +import React from "react"; +import CompletionClient from "../../clients/CompletionClient"; +import CompletionType from "../../../shared/CompletionType"; + +const completionClient = new CompletionClient(); + +export const useGetCompletionTypes = (): [ + CompletionType[] | undefined, + boolean +] => { + type State = { + loading: boolean; + result?: CompletionType[]; + }; + const [state, setState] = React.useState<State>({ loading: true }); + + React.useEffect(() => { + completionClient.getCompletionTypes().then((result) => { + setState({ loading: false, result }); + }); + }, []); + return [state.result, state.loading]; +}; |