fix
This commit is contained in:
parent
fa0703340a
commit
fa787fe6af
|
@ -24,6 +24,10 @@ export function useApi<T>(
|
||||||
|
|
||||||
const execute = useCallback(
|
const execute = useCallback(
|
||||||
async (...args: any[]): Promise<T | null> => {
|
async (...args: any[]): Promise<T | null> => {
|
||||||
|
if (!endpoint) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
@ -42,7 +46,7 @@ export function useApi<T>(
|
||||||
case 'PUT':
|
case 'PUT':
|
||||||
response = await axios.put<T>(`${API_URL}${endpoint}`, args[0], { headers });
|
response = await axios.put<T>(`${API_URL}${endpoint}`, args[0], { headers });
|
||||||
break;
|
break;
|
||||||
case 'PATCH': // Добавляем поддержку PATCH-запросов
|
case 'PATCH':
|
||||||
response = await axios.patch<T>(`${API_URL}${endpoint}`, args[0], { headers });
|
response = await axios.patch<T>(`${API_URL}${endpoint}`, args[0], { headers });
|
||||||
break;
|
break;
|
||||||
case 'DELETE':
|
case 'DELETE':
|
||||||
|
@ -73,7 +77,6 @@ export function useApi<T>(
|
||||||
return { data, loading, error, execute };
|
return { data, loading, error, execute };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Вспомогательные функции для типичных запросов
|
|
||||||
export function useGet<T>(endpoint: string) {
|
export function useGet<T>(endpoint: string) {
|
||||||
return useApi<T>(endpoint, 'GET');
|
return useApi<T>(endpoint, 'GET');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue