This commit is contained in:
itqop 2025-02-11 13:05:07 +03:00
parent fa0703340a
commit fa787fe6af
1 changed files with 5 additions and 2 deletions

View File

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