State

state/query-object-syntax

TanStack Query 5 hooks take one options object; the v4 positional form useQuery(key, fn) and useMutation(fn) no longer works.

seriousstaticfe-data-fetching

Why

Version 5 removed the overloads that took the key, the function and the options as separate arguments. Code copied from older tutorials, or written from memory by an agent, fails type checking or throws at run time after an upgrade.

Fix

Pass one object: useQuery({ queryKey: ['todos'], queryFn: getTodos }), useMutation({ mutationFn: addTodo }). While upgrading, also rename cacheTime to gcTime and isLoading (first load) to isPending.

Examples

// bad
useQuery(['todos'], getTodos, { staleTime: 60_000 })
useMutation((todo) => addTodo(todo))
// good
useQuery({ queryKey: ['todos'], queryFn: getTodos, staleTime: 60_000 })
useMutation({ mutationFn: addTodo })

Sources

Facts

Id
state/query-object-syntax
Severity
serious
Check
static checked in the source by audit
Applies to
jsx vue svelte
Only in projects with
tanstack-query
Taught by the skill
fe-data-fetching Data fetching
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain state/query-object-syntax