blob: d3c45429e5b1a2dc63f0b193ab7ed2642eb6629b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import useSWR, { responseInterface } from 'swr';
import { get } from '../requests';
import { User, Event } from '../types';
type Response<T> = responseInterface<T, Error>;
const fetcher = (endpoint: string) => get(endpoint).then(response => response.data);
export const useUser = (id: string): Response<User> => {
return useSWR(id && `/users/${id}`, fetcher);
};
export const useEvents = (): Response<Event[]> => {
return useSWR(`/events`, fetcher);
};
|