react-query-mutative

Implement optimistic updates in React Query mutations with rollback and toast error handling.

Updated Apr 5, 2026
One-click install
npx skills add https://github.com/harryy2510/dotclaude --skill react-query-mutative
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-query-mutative
Source: https://github.com/harryy2510/dotclaude/tree/main/plugins/dotclaude/skills/react-query-mutative
Command: npx skills add https://github.com/harryy2510/dotclaude --skill react-query-mutative

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Efficiently manage optimistic UI updates and data consistency in React applications by providing structured mutative utilities and QueryClient configuration guidance.

Core Features & Use Cases

  • Centralized QueryClient configuration with deterministic behavior (staleTime: Infinity, gcTime: Infinity, refetchOnMount: false, refetchOnWindowFocus: false, retry: false) and toast-based error handling for mutations and queries.
  • Query Key factories to consistently derive keys for domains and queries.
  • Mutative helpers for optimistic updates, add/remove, and safe rollback semantics in mutations.
  • Clear guidance on invalidateQueries vs refetchQueries and when to use each.
  • Scalable API module pattern across domains.

Quick Start

Use mutative helpers to apply optimistic updates during a mutation and automatically rollback on error.

Frequently Asked Questions about react-query-mutative

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

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

Implement optimistic updates in React Query by applying mutative helpers within the onMutate lifecycle to update the cache immediately, and return previous state snapshots to enable automatic rollback on mutation failure.

What's the best way to rollback failed mutations in React Query?

Rollback failed mutations in React Query by capturing the previous cache state during onMutate and restoring it inside the onError handler to safely revert optimistic UI updates when the request fails.

When should I use invalidateQueries vs refetchQueries in React Query?

Use invalidateQueries to mark query data as stale for passive background refetching, and use refetchQueries when you must actively force a network request immediately following a successful mutation.

How do I structure query keys for multiple domains in a React Query API?

Structure query keys for multiple domains using query key factories that consistently derive keys for specific domains and queries, ensuring a scalable API module pattern across your React application.

Why does my React Query client refetch data on window focus when using optimistic updates?

Your React Query client refetches on window focus because the default configuration overrides mutation behavior. Set refetchOnWindowFocus to false in your QueryClient configuration to prevent overriding optimistic state.