ts-quiz— ~/quiz/levels.ts
tsc --watch● loading…
// tsc --watch · type-checking modules…
await load("quiz/levels.ts")
// streaming server components
◇ tsc 6.0.3 · compiling…UTF-8◇ scanning levels…
useFetch usa el generic <T,>?const useFetch = <T,>(url: string) => {
const [data, setData] = useState<T | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);
useEffect(() => {
fetch(url)
.then((res) => res.json())
.then((json: T) => setData(json))
.catch((err) => setError(err))
.finally(() => setLoading(false));
}, [url]);
return { data, loading, error };
};
const { data } = useFetch<User[]>("/api/users");