diff options
author | eug-vs <eug-vs@keemail.me> | 2020-08-09 19:51:32 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-08-09 19:51:32 +0300 |
commit | b6f9dbc3cbb21447fdeb22420b005da37de2af8e (patch) | |
tree | 158ecaac5a7bdabd4519fb8347bd92dce80dfea5 /src/hooks/APIClient.ts | |
parent | 74d34ff5072d2582cf825121e901eed3401e63b9 (diff) | |
download | which-ui-b6f9dbc3cbb21447fdeb22420b005da37de2af8e.tar.gz |
feat: use SWR in profile page
Diffstat (limited to 'src/hooks/APIClient.ts')
-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..fa23a21 --- /dev/null +++ b/src/hooks/APIClient.ts @@ -0,0 +1,17 @@ +import useSWR from 'swr'; +import { get } from '../requests'; + + +const fetcher = (endpoint: string) => get(endpoint).then(response => response.data); + + +export const useUser = (username: string) => { + return useSWR( + `/users?username=${username}`, + (url: string) => get(url).then(response => response.data[0]) + ); +}; + +export const useProfile = (id: string) => { + return useSWR(id && `/profiles/${id}`, fetcher, { initialData: [] }); +}; |