summaryrefslogtreecommitdiff
path: root/src/hooks/useAPIClient.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/hooks/useAPIClient.ts')
-rw-r--r--src/hooks/useAPIClient.ts15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/hooks/useAPIClient.ts b/src/hooks/useAPIClient.ts
index 1fa9896..adb6d3f 100644
--- a/src/hooks/useAPIClient.ts
+++ b/src/hooks/useAPIClient.ts
@@ -1,13 +1,14 @@
import useSWR, { responseInterface } from 'swr';
import _ from 'lodash';
import { get } from '../requests';
-import services from '../services';
type Response<T> = responseInterface<T, Error>;
const fetcher = (endpoint: string) => get(endpoint).then(response => response.data);
-const createServiceHooks = <Item = any>(service: string) => {
+const hooks: any = {};
+
+const registerServiceHooks = <Item = any>(service: string) => {
const useList = (query = '', options = {}): Response<Item[]> => {
return useSWR(`/${service}${query}`, fetcher, options);
};
@@ -24,7 +25,7 @@ const createServiceHooks = <Item = any>(service: string) => {
return result;
};
- return { useItem, useList };
+ hooks[service] = { useItem, useList };
};
// Products
@@ -49,11 +50,6 @@ export interface Contractor {
debt: number;
}
-const hooks = services.reduce((acc, { route }) => {
- return _.set(acc, route, createServiceHooks(route));
-}, {});
-
-
hooks.account = {
useList: () => {
const { data: transfers } = useSWR('/transfers', fetcher);
@@ -70,4 +66,5 @@ hooks.account = {
};
-export default hooks as any;
+export { registerServiceHooks };
+export default hooks;