diff options
author | eug-vs <eug-vs@keemail.me> | 2020-11-14 23:11:06 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-11-14 23:11:06 +0300 |
commit | f96e6174fe90f3d2b1e3016861017cfcc25a6ddc (patch) | |
tree | 74baaa47fc42e11c48c2e82c2ce3ae788d9b303c /src/hooks | |
parent | b978e6a4958cb543bd73259ec6d43e98dfb7ae18 (diff) | |
download | famcs-kit-f96e6174fe90f3d2b1e3016861017cfcc25a6ddc.tar.gz |
feat: add APIClient
Diffstat (limited to 'src/hooks')
-rw-r--r-- | src/hooks/APIClient.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/hooks/APIClient.ts b/src/hooks/APIClient.ts new file mode 100644 index 0000000..d3c4542 --- /dev/null +++ b/src/hooks/APIClient.ts @@ -0,0 +1,17 @@ +import useSWR, { responseInterface } from 'swr'; +import { get } from '../requests'; +import { User, Event } from '../types'; + +type Response<T> = responseInterface<T, Error>; + +const fetcher = (endpoint: string) => get(endpoint).then(response => response.data); + + +export const useUser = (id: string): Response<User> => { + return useSWR(id && `/users/${id}`, fetcher); +}; + +export const useEvents = (): Response<Event[]> => { + return useSWR(`/events`, fetcher); +}; + |