TanStack Query v5 is a major release of the popular server-state management library, simplifying the API surface while significantly improving TypeScript support.
All hooks now accept a single options object — positional argument overloads have been removed:
// v4
useQuery(['todos'], fetchTodos, { staleTime: 5000 });
// v5
useQuery({ queryKey: ['todos'], queryFn: fetchTodos, staleTime: 5000 });
v5 infers the return type of queryFn automatically without requiring explicit generics in most cases. Error types are now unknown by default, encouraging proper error handling.
const pendingPosts = useMutationState({
filters: { mutationKey: ['addPost'], status: 'pending' },
select: (mutation) => mutation.state.variables,
});
npx jscodeshift -t @tanstack/query-codemods/v5/rename-properties.js ./src
All Comments