Stan aplikacji
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.
poważnastatycznefe-data-fetching
Dlaczego
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.
Poprawka
Pass one object: useQuery({ queryKey: ['todos'], queryFn: getTodos }), useMutation({ mutationFn: addTodo }). While upgrading, also rename cacheTime to gcTime and isLoading (first load) to isPending.
Przykłady
// bad
useQuery(['todos'], getTodos, { staleTime: 60_000 })
useMutation((todo) => addTodo(todo))
// good
useQuery({ queryKey: ['todos'], queryFn: getTodos, staleTime: 60_000 })
useMutation({ mutationFn: addTodo })Źródła
Fakty
- Identyfikator
state/query-object-syntax- Waga
- poważna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
jsxvuesvelte- Tylko w projektach z
tanstack-query- Uczy jej skill
fe-data-fetchingData fetching- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain state/query-object-syntax