The platform for continuously improving AI agents.
import { useInfiniteQuery } from "@tanstack/react-query";
import apiClient from "@/client";
import type { PaginatedExperimentListList } from "@/openapi";
const PAGE = 50;
/** The project's experiments, newest first, a page at a time. */
export function useExperimentsQuery(projectId: string | undefined) {
return useInfiniteQuery({
enabled: !!projectId,
getNextPageParam: (page: PaginatedExperimentListList, pages) =>
page.next ? pages.length + 1 : undefined,
initialPageParam: 1,
queryFn: ({ pageParam }) =>
apiClient.researchExperiments.researchExperimentsList({
ordering: "-created_at",
page: pageParam,
pageSize: PAGE,
project: projectId,
}),
queryKey: ["research-experiments", projectId, "pages"],
select: (data) => ({ ...data, pages: data.pages.map((page) => page.results) }),
});
}