summaryrefslogtreecommitdiff
path: root/src/hooks
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-14 02:32:09 +0300
committereug-vs <eug-vs@keemail.me>2021-03-14 02:32:26 +0300
commit64a537425a05a15ecfac3bf314735876dbbd8ed7 (patch)
tree526d83464a470ee8311744b4736ae7545c0fcd30 /src/hooks
parentcfb287490d353166cf0a3db7105d8002cc473f00 (diff)
downloadcommercel-ui-64a537425a05a15ecfac3bf314735876dbbd8ed7.tar.gz
feat: pull Products from api
Diffstat (limited to 'src/hooks')
-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);
+};