summaryrefslogtreecommitdiff
path: root/src/hooks/useAPIClient.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/hooks/useAPIClient.ts')
-rw-r--r--src/hooks/useAPIClient.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/hooks/useAPIClient.ts b/src/hooks/useAPIClient.ts
new file mode 100644
index 0000000..a27453e
--- /dev/null
+++ b/src/hooks/useAPIClient.ts
@@ -0,0 +1,21 @@
+import useSWR, { responseInterface } from 'swr';
+import { get } from '../requests';
+
+type Response<T> = responseInterface<T, Error>;
+
+export interface Product {
+ _id: string;
+ name: string;
+ description: string;
+ price: number;
+ quantity: number;
+ specs: any;
+ createdAt: string;
+ updatedAt: string;
+}
+
+const fetcher = (endpoint: string) => get(endpoint).then(response => response.data);
+
+export const useProducts = (): Response<Product[]> => {
+ return useSWR('/products', fetcher);
+};