import useSWR, { responseInterface } from 'swr'; import { get } from '../requests'; import { User, Event } from '../types'; type Response = responseInterface; const fetcher = (endpoint: string) => get(endpoint).then(response => response.data); export const useUser = (username: string | null): Response => { return useSWR( username && `/users?username=${username}`, (url: string) => get(url).then(response => response.data[0]) ); }; export const useEvents = (): Response => { return useSWR(`/events`, fetcher); };