import { useApiGetProjectList } from "@/api/cubicweb"; import { Project } from "@/types"; import { useState, useEffect } from "react"; import { useHandleAuthErrors } from "./useHandleAuthErrors"; export function useGetProjectList() { const [loading, setLoading] = useState(true); const [data, setData] = useState<Array<Project> | undefined>(undefined); const handleAuthErrors = useHandleAuthErrors(); const getProjectList = useApiGetProjectList(); useEffect(() => { setLoading(true); getProjectList() .then((result) => { setLoading(false); setData(result); }) .catch(handleAuthErrors); }, [handleAuthErrors]); return { loading, data }; }