chore: change styles and add Api for user profile

This commit is contained in:
Koosha Lahouti
2025-08-12 20:20:28 +03:30
parent ed57858c2e
commit 782ef2a2de
35 changed files with 2785 additions and 1843 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 };
}