calypso-react-query-migration

Migrates Calypso Reader data fetching from Redux and data-stores to React Query.

12.6k|2.0k|Updated Nov 10, 2015
One-click install
npx skills add https://github.com/Automattic/wp-calypso --skill calypso-react-query-migration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: calypso-react-query-migration
Source: https://github.com/Automattic/wp-calypso/tree/main/.claude/skills/calypso-react-query-migration
Command: npx skills add https://github.com/Automattic/wp-calypso --skill calypso-react-query-migration

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Migrating WordPress.com Calypso Reader data-fetching code from legacy Redux data-layer handlers and @automattic/data-stores hooks to the @automattic/api-core and @automattic/api-queries React Query architecture is error-prone, with risks like orphaned cache keys, partial CRUD migrations, and stale UI state.

Core Features & Use Cases

  • Structured Migration Workflow: Enforces a plan-first process with CRUD audits, cache-key consumer checks, and bridge-component decisions before any code changes.
  • Fetcher and Query Scaffolding: Provides naming conventions and code templates for fetchers in api-core, query/mutation options in api-queries, and optional QueryReader bridge components.
  • Redux Cleanup Guidance: Covers surgical removal of action types, reducers, selectors, and connect() HOCs, including an HOC pattern for class components.
  • Use Case: When asked to migrate a QueryReaderTag component, the Skill audits all READER_* actions, plans the migration, creates fetchReadTag and readTagQuery, updates consumers, and removes the Redux slice in a separate commit.

Quick Start

Migrate the QueryReaderTag component and its Redux data-layer handlers to React Query following the api-core and api-queries architecture.

Frequently Asked Questions about calypso-react-query-migration

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

FAQPage Schema
How do I migrate a Calypso Reader Redux query to React Query?

Create a fetcher in packages/api-core/src/read-{name}/fetchers.ts using wpcom from ../wpcom-fetcher, add query options in packages/api-queries/src/read-{name}.ts with queryOptions, then update consumers to call useQuery. Audit all CRUD actions first and write a plan before editing.

How do I migrate @automattic/data-stores Reader hooks to api-queries?

Swap the data-stores hook import for useQuery with the matching read{Name}Query from @automattic/api-queries, preserving the same queryKey for mid-session cache compatibility. No bridge component is needed, and the migration lands in a single commit.

When should I keep the QueryReader bridge component?

Keep the bridge when many consumers or cross-codebase selectors still read the Redux slice, and record the reason in the plan. Remove it when only one to three function components consume the data, adapting them to useQuery directly.

Why does the UI show stale data after a React Query mutation?

Stale data usually means missing cache invalidation or an orphaned query key. Mutations need invalidateQueries or removeQueries in onSuccess, and any key change requires updating every consumer found by grepping for the old key segment.

Should React Query mutations in Calypso use optimistic updates?

Yes, default to optimistic updates for user-facing mutations using onMutate with cancelQueries, a snapshot for rollback, and onSettled invalidation. Skip them only when results depend on server-computed values the client cannot predict.

Can class components use React Query during the migration?

Hooks cannot run inside class components, so wrap the class in a functional HOC that calls useQuery and forwards results as props. Do not rewrite class components to function components as part of a data migration.