tanstack-react-query-mutations

Implement TanStack Query mutations with optimistic updates and cache invalidation.

5|Updated Feb 12, 2026
One-click install
npx skills add https://github.com/agusmdev/fullstack-ai-template --skill tanstack-react-query-mutations
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-react-query-mutations
Source: https://github.com/agusmdev/fullstack-ai-template/tree/main/.claude/skills/tanstack-react-query-mutations
Command: npx skills add https://github.com/agusmdev/fullstack-ai-template --skill tanstack-react-query-mutations

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Mutations in UI-heavy apps can lead to stale data and inconsistent UX. This skill provides a standardized set of mutation patterns (create, update, and delete) using TanStack Query's useMutation, with optimistic updates, error handling, and robust rollback and cache-invalidation strategies.

Core Features & Use Cases

  • Mutation patterns for create, update, and delete using TanStack Query's useMutation, including onMutate, onSuccess, onError, and onSettled.
  • Cache management through invalidation and optimistic updates to keep lists and details in sync.
  • Real-world use case: updating a user profile and reflecting changes instantly while syncing with the server.

Quick Start

Instantiate the provided useMutation hooks in your React components and integrate them with your UI to manage mutations.

Frequently Asked Questions about tanstack-react-query-mutations

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement optimistic updates with TanStack Query mutations?

Optimistic updates with TanStack Query mutations are implemented using the onMutate lifecycle to update the cache immediately, onSuccess to confirm changes, and onError to roll back if the server request fails.

What's the best way to handle error rollback in React Query useMutation?

Error rollback in React Query useMutation is handled within the onError callback by invalidating the query cache or restoring the previous query data captured during onMutate, ensuring UI consistency after failures.

Does this mutation pattern work with both TanStack Start SSR and SPA Router?

Yes, these mutation patterns support both SSR with TanStack Start and SPA with TanStack Router, applying consistent cache invalidation and optimistic update workflows across create, update, and delete operations.

How do I keep list and detail caches in sync after a React Query mutation?

List and detail caches stay in sync after a React Query mutation by triggering query invalidation in the onSettled or onSuccess callbacks, forcing TanStack Query to refetch the updated data from the API layer.

Why do my TanStack Query optimistic updates disappear on error?

TanStack Query optimistic updates disappear on error because the onError lifecycle triggers a rollback to the previous cache state, undoing the speculative onMutate changes when the API mutation request fails.

Do I need a specific API layer setup to use TanStack Query mutations?

Yes, you need a configured API layer and an established UI integration pattern alongside TanStack Query to handle data fetching and ensure deterministic behavior and graceful recovery from failures.