Dashboard, agents, goals, issues, and projects pages with sidebar navigation. API client layer, custom hooks, and shared layout components. Built with Vite and TypeScript. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
22 lines
545 B
TypeScript
22 lines
545 B
TypeScript
import { useState, useEffect, useCallback } from "react";
|
|
|
|
export function useApi<T>(fetcher: () => Promise<T>) {
|
|
const [data, setData] = useState<T | null>(null);
|
|
const [error, setError] = useState<Error | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
const load = useCallback(() => {
|
|
setLoading(true);
|
|
fetcher()
|
|
.then(setData)
|
|
.catch(setError)
|
|
.finally(() => setLoading(false));
|
|
}, [fetcher]);
|
|
|
|
useEffect(() => {
|
|
load();
|
|
}, [load]);
|
|
|
|
return { data, error, loading, reload: load };
|
|
}
|