aboutsummaryrefslogtreecommitdiff
path: root/src/hooks/APIClient.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/hooks/APIClient.ts')
-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: [] });
+};