import { useEffect, useState } from "react";
import { type FullProjectSchema, ProjectService } from "../client";


const useProjects = () => {
    const [projects, setProjects] = useState<FullProjectSchema[]>([]);

    const refetchProjects = () => {
        ProjectService.getProjects()
            .then(data => {
                setProjects(data.projects);
            })
            .catch(e => console.log(e));
    };

    useEffect(() => {
        refetchProjects();
    }, []);

    return {
        projects,
        refetchProjects,
    };
};

export default useProjects;
