diff options
author | eug-vs <eug-vs@keemail.me> | 2020-08-14 04:09:56 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-08-14 04:19:52 +0300 |
commit | 917d83bfb70d863944df62fb3ca254ba74e67e6e (patch) | |
tree | f3739faea2ad5ee23d083d2ab1d23f67db1a9170 /src/hooks | |
parent | dc0d09f568ca9eeda4978c4750b548ba81688c23 (diff) | |
download | which-ui-917d83bfb70d863944df62fb3ca254ba74e67e6e.tar.gz |
feat: add EmptyState component
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[]>; }; |