blob: a27453e4467f6ebe5dedfd5523920aa49f9ecc90 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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);
};
|