T
TanStack•5mo ago
harsh-harlequin

Am I using Tanstack Query wrong?

I have a tab with users and admins, when you press the users tab it fetches the users and when you press admins it fetches the admin. But when I am pressing the tabs back and forth the server then freezes, but it is really minimal data coming through, it is the server that is the issue or the way I am fetching the data
5 Replies
harsh-harlequin
harsh-harlequinOP•5mo ago
const { isLoading, data, isError, error, refetch, isFetching } = useQuery({
queryKey: ["users"],
queryFn: endpoint === "admin" ? fetchAdmins : fetchUsers,
retryOnMount: true,
})
const { isLoading, data, isError, error, refetch, isFetching } = useQuery({
queryKey: ["users"],
queryFn: endpoint === "admin" ? fetchAdmins : fetchUsers,
retryOnMount: true,
})
fair-rose
fair-rose•5mo ago
please provide a complete minimal example git repo
harsh-harlequin
harsh-harlequinOP•5mo ago
@Manuel Schiller I figured the issue out, it was a database issue. just a small question the ternary I added for queryFn is that okay to do or is it bad practice?
fair-rose
fair-rose•5mo ago
depends on where endpoint comes from I would probably define two different query options
harsh-harlequin
harsh-harlequinOP•5mo ago
thank you for the advice, I will do that 🙂

Did you find this page helpful?