diff options
Diffstat (limited to 'src/hooks')
-rw-r--r-- | src/hooks/APIClient.ts | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/src/hooks/APIClient.ts b/src/hooks/APIClient.ts index 9563bd6..f66ef2e 100644 --- a/src/hooks/APIClient.ts +++ b/src/hooks/APIClient.ts @@ -2,18 +2,10 @@ import useSWR, { responseInterface } from 'swr'; import { User, Poll, Feedback } from 'which-types'; import { get } from '../requests'; - -interface Response<T> extends responseInterface<T, Error> { - data: T; -} +type Response<T> = responseInterface<T, Error>; const fetcher = (endpoint: string) => get(endpoint).then(response => response.data); -const arrayOptions = { - initialData: [], - revalidateOnMount: true -}; - export const useUser = (username: string | null): Response<User> => { return useSWR( username && `/users?username=${username}`, @@ -22,13 +14,13 @@ export const useUser = (username: string | null): Response<User> => { }; export const useProfile = (id: string): Response<Poll[]> => { - return useSWR(id && `/profiles/${id}`, fetcher, arrayOptions) as Response<Poll[]>; + return useSWR(id && `/profiles/${id}`, fetcher) as Response<Poll[]>; }; export const useFeed = (): Response<Poll[]> => { - return useSWR('/feed', fetcher, { ...arrayOptions, revalidateOnFocus: false }) as Response<Poll[]>; + return useSWR('/feed', fetcher, { revalidateOnFocus: false }) as Response<Poll[]>; }; export const useFeedback = (): Response<Feedback[]> => { - return useSWR('/feedback', fetcher, arrayOptions) as Response<Feedback[]>; + return useSWR('/feedback', fetcher) as Response<Feedback[]>; }; |