blob: 015191c881b24bf849be62e1e7f22d89276a79fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
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 = (username: string | null): Response<User> => {
return useSWR(
username && `/users?username=${username}`,
(url: string) => get(url).then(response => response.data[0])
);
};
export const useEvents = (): Response<Event[]> => {
return useSWR(`/events`, fetcher);
};
|