---
title: "Creating Query Abstractions"
url: https://daily.dev/posts/creating-query-abstractions-fqwkcndj0
source_url: https://tkdodo.eu/blog/creating-query-abstractions
type: article
source: "TkDodo"
published: 2026-02-23T18:21:05.963Z
updated: 2026-02-23T18:21:31.835Z
tags: ["react", "typescript"]
reading_time: 7
upvotes: 31
comments: 1
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating Query Abstractions

**[TkDodo](https://daily.dev/sources/tkdodo)** · 7 min read · 31 upvotes · 1 comments

## Summary

Custom hooks are a common but flawed way to abstract TanStack Query usage. Wrapping useQuery in a custom hook breaks TypeScript type inference when passing options like UseQueryOptions without explicit generics, and limits usage to React component contexts only. The queryOptions API (introduced in TanStack Query v5) is a better abstraction: it's a plain function usable anywhere (hooks, server, route loaders, prefetching), preserves full type inference, and composes cleanly by spreading additional options at call sites rather than threading them through parameters.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://tkdodo.eu/blog/creating-query-abstractions>

## Community discussion

Top comments from developers on daily.dev.

**@ujevicigor** · 0 upvotes

> Nice post! Since I am big TanStack Query fan, I’ve written something similar - would appreciate it if you could check it out: [TanStack Query vs SWR](https://medium.com/@ujevicigor/tanstack-query-vs-swr-choosing-the-right-data-fetching-library-7579d7fad1c8)

## Similar posts on daily.dev

- [A gentle introduction to TanStack Query](https://daily.dev/posts/a-gentle-introduction-to-tanstack-query-e5yjmxkk9) · Neciu Dan · 79 upvotes · 5 comments

---

Tags: [#react](https://daily.dev/tags/react), [#typescript](https://daily.dev/tags/typescript)

[View this post on daily.dev](https://daily.dev/posts/creating-query-abstractions-fqwkcndj0)
