Skip to content

Instantly share code, notes, and snippets.

@raphox
Created August 2, 2023 11:32
Show Gist options
  • Save raphox/023888caec923f8ccb15aa33be010a55 to your computer and use it in GitHub Desktop.
Save raphox/023888caec923f8ccb15aa33be010a55 to your computer and use it in GitHub Desktop.
frontend/src/services/index.ts
import { api } from "@/services";
import { useQuery } from "@tanstack/react-query";
export type Document = {
id: string;
title: string;
description: string;
link: string;
created_at: Date;
updated_at: Date;
};
export const findAll = async (query?: Record<string, any>) => {
const response = await api.get<Document[]>("documents", {
params: { ...query },
});
return response.data;
};
export function useDocuments(query?: Record<string, any>) {
const {
data,
isFetching,
refetch: getAllDocuments,
} = useQuery(["documents"], async () => await findAll(query));
return {
documents: data,
isLoading: isFetching,
getAllDocuments,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment