import {useQuery, useMutation, useQueryClient} from "@tanstack/react-query";
import {fetch_} from "../request-utils";
import {useConfig} from "../../ConfigProvider";


export const useTree = () => {
    const queryClient = useQueryClient();
    const config = useConfig();
    return useQuery({
        queryKey: ["tree"],
        queryFn: () => fetch_(`${config.BACKEND_HOST}/api/tree/`),
        onSuccess: data => {
            if(data)
                queryClient.setQueryData({queryKey: ["tree"]}, data);
        }
    });
};
