aboutsummaryrefslogtreecommitdiff
path: root/src/hooks
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-08-14 05:06:01 +0300
committerGitHub <noreply@github.com>2020-08-14 05:06:01 +0300
commita6d2d1d833116772178125b3e047e0811131c0e0 (patch)
tree022abcb444cda09f98c2d43accc2fdd85aeb2a82 /src/hooks
parentdc0d09f568ca9eeda4978c4750b548ba81688c23 (diff)
parent1d35dd8a80f0ea72306e96c2229a27798ec75ce9 (diff)
downloadwhich-ui-a6d2d1d833116772178125b3e047e0811131c0e0.tar.gz
Merge pull request #81 from which-ecosystem/better-ux
Handle empty states
Diffstat (limited to 'src/hooks')
-rw-r--r--src/hooks/APIClient.ts16
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[]>;
};