- Initial response set to null; Frontend now generates a list of anticipated stats; - Background evaluation dynamically updates DB upon completion; - Frontend actively monitors and finalizes upon stat evaluation completion.
20 lines
565 B
TypeScript
20 lines
565 B
TypeScript
import {Stat, User} from "@/interfaces/user";
|
|
import axios from "axios";
|
|
import {useEffect, useState} from "react";
|
|
|
|
export default function useStats(id?: string) {
|
|
const [stats, setStats] = useState<Stat[]>([]);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [isError, setIsError] = useState(false);
|
|
|
|
useEffect(() => {
|
|
setIsLoading(true);
|
|
axios
|
|
.get<Stat[]>(!id ? "/api/stats" : `/api/stats/user/${id}`)
|
|
.then((response) => setStats(response.data))
|
|
.finally(() => setIsLoading(false));
|
|
}, [id]);
|
|
|
|
return {stats, isLoading, isError};
|
|
}
|