Skip to content
Home / Migrations / TanStack Query v4TanStack Query v5

TanStack Query v4 TanStack Query v5

medium

v5 simplifies the API to single-object signatures and renames a few options. Most upgrades take an hour with the codemod.

Estimated: 2-5h · 5 steps
Progress0%
Step 1: Run codemod
npx @tanstack/query-codemods v5/remove-overloads.cjs ./src
Step 2: Rename cacheTime → gcTime

Find/replace across the codebase or rely on the codemod.

Step 3: Remove onSuccess/onError/onSettled

Side effects move to useEffect or to mutation-level callbacks. useQuery callbacks were removed.

useEffect(() => { if (query.data) trackEvent('loaded') }, [query.data])
Step 4: Switch isLoading semantics

isLoading → isPending (no cached data + first fetch). isFetching unchanged. Update conditions accordingly.

Step 5: Update Suspense usage

Use useSuspenseQuery instead of useQuery({ suspense: true }).

All queries refetch correctly. No type errors. Devtools show v5.