TLDR Dev · ARTICLES & TUTORIALS

CREATING QUERY ABSTRACTIONS

tkdodo.eu8 min read

Summary from the TLDR Dev newsletter

Custom hooks are the wrong way to abstract useQuery, as they lock you into one hook, get messy with TypeScript generics, and can't be used outside components. Instead, use queryOptions to define your key and fetch function once, then spread it into whatever hook you need (useQuery, useSuspenseQuery, etc.) with per-usage options on top.