TanStackT
TanStack13mo ago
2 replies
foolish-indigo

What are some common practices regarding queryOption abstractions?

I basically have two hooks for each API request now. One is strictly queryOptions that utilize the queryKey and queryFn that allows me to spread into any useQuery hook.

For most of my API handlers i abstract it even more by doing something like useResource().

These call useQuery and spread in the queryOptions.

The most annoying part is handling types. The queryFn itself validates props (so it can correctly return an Error that RQ can consume), and so props coming into every other hook must be partial. This however does not give confidence to the developer what is actually needed and what is optional.

So I’m curious how other people use abstraction with RQ
Was this page helpful?