fix: styles

This commit is contained in:
Koosha Lahouti
2025-08-12 02:51:24 +03:30
parent 437245f54f
commit 6cb742ff39
4 changed files with 360 additions and 7 deletions

26
src/hooks/useApi.ts Normal file
View File

@@ -0,0 +1,26 @@
import { useState, useEffect } from 'react';
type ApiFunction<T> = () => Promise<{ data: T }>;
export function useApi<T>(apiFunction: ApiFunction<T>) {
const [data, setData] = useState<T | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<unknown>(null);
useEffect(() => {
const fetchData = async () => {
try {
const response = await apiFunction();
setData(response.data);
} catch (err) {
setError(err);
} finally {
setLoading(false);
}
};
fetchData();
}, [apiFunction]);
return { data, loading, error };
}