mirror of
https://github.com/umami-software/umami.git
synced 2026-02-13 09:05:36 +01:00
Added useApi hook.
This commit is contained in:
parent
7bd49e6caf
commit
d19b6b5a82
22 changed files with 59 additions and 59 deletions
25
hooks/useApi.js
Normal file
25
hooks/useApi.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { useCallback } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { get, post, put, del } from 'lib/web';
|
||||
|
||||
export default function useApi() {
|
||||
const { basePath } = useRouter();
|
||||
|
||||
return {
|
||||
get: useCallback(async (url, params, headers) => {
|
||||
return get(`${basePath}/api/${url}`, params, headers);
|
||||
}, []),
|
||||
|
||||
post: useCallback(async (url, params, headers) => {
|
||||
return post(`${basePath}/api/${url}`, params, headers);
|
||||
}, []),
|
||||
|
||||
put: useCallback(async (url, params, headers) => {
|
||||
return put(`${basePath}/api/${url}`, params, headers);
|
||||
}, []),
|
||||
|
||||
del: useCallback(async (url, params, headers) => {
|
||||
return del(`${basePath}/api/${url}`, params, headers);
|
||||
}, []),
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue