Created
August 2, 2023 11:32
-
-
Save raphox/023888caec923f8ccb15aa33be010a55 to your computer and use it in GitHub Desktop.
frontend/src/services/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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