From 64a537425a05a15ecfac3bf314735876dbbd8ed7 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 14 Mar 2021 02:32:09 +0300 Subject: feat: pull Products from api --- src/hooks/useAPIClient.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/hooks/useAPIClient.ts (limited to 'src/hooks') 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 = responseInterface; + +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 => { + return useSWR('/products', fetcher); +}; -- cgit v1.2.3