Skip to content
Snippets Groups Projects
useGetProjectList.tsx 696 B
Newer Older
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();
    getProjectList()
      .then((result) => {
        setLoading(false);
        setData(result);
      })
      .catch(handleAuthErrors);
  }, [handleAuthErrors]);