aboutsummaryrefslogtreecommitdiff
path: root/src/hooks/APIClient.ts
blob: fa23a21971e78c96c9fa8522598b5b34f845faf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import useSWR from 'swr';
import { get } from '../requests';


const fetcher = (endpoint: string) => get(endpoint).then(response => response.data);


export const useUser = (username: string) => {
  return useSWR(
    `/users?username=${username}`,
    (url: string) => get(url).then(response => response.data[0])
  );
};

export const useProfile = (id: string) => {
  return useSWR(id && `/profiles/${id}`, fetcher, { initialData: [] });
};