aboutsummaryrefslogtreecommitdiff
path: root/src/hooks
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-08-09 19:51:32 +0300
committereug-vs <eug-vs@keemail.me>2020-08-09 19:51:32 +0300
commitb6f9dbc3cbb21447fdeb22420b005da37de2af8e (patch)
tree158ecaac5a7bdabd4519fb8347bd92dce80dfea5 /src/hooks
parent74d34ff5072d2582cf825121e901eed3401e63b9 (diff)
downloadwhich-ui-b6f9dbc3cbb21447fdeb22420b005da37de2af8e.tar.gz
feat: use SWR in profile page
Diffstat (limited to 'src/hooks')
-rw-r--r--src/hooks/APIClient.ts17
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: [] });
+};