react-patterns

Guides writing and reviewing React components, hooks, state placement, and data fetching patterns.

Updated Aug 3, 2026
One-click install
npx skills add https://github.com/m-de-graaff/skills --skill react-patterns-m-de-graaff
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: react-patterns
Source: https://github.com/m-de-graaff/skills/tree/main/skills/react-patterns
Command: npx skills add https://github.com/m-de-graaff/skills --skill react-patterns-m-de-graaff

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? React codebases accumulate subtle defects: derived state synced through useEffect, useEffect-plus-fetch data loading with race conditions, misplaced state, and misused hooks. This Skill provides opinionated, idiomatic React 18/19 guidance so components are written and reviewed against proven patterns instead of rediscovering bugs in production. ## Core Features & Use Cases - Hook selection guidance: A decision table mapping each hook (useReducer, useSyncExternalStore, useOptimistic, useActionState, useFormStatus, and more) to the exact problem it solves, including React 19 changes like ref-as-prop. - State placement and architecture: Rules for where state lives (local, lifted, Context, external store, server cache) and how to compose Server and Client Components without breaking serialization or security boundaries. - Data fetching, forms, and boundaries: Patterns for TanStack Query/SWR/RSC fetching, React 19 form actions, and correct Suspense and error boundary placement. - Use Case: While reviewing a pull request, you notice a useEffect that only copies props into state and a useEffect-plus-fetch for server data. This Skill flags both as red-flag patterns and shows the correct replacements. ## Quick Start Ask the assistant to review this React component for idiomatic patterns and hook usage before merging it.

Frequently Asked Questions about react-patterns

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

FAQPage Schema
How do I fetch data in React without useEffect?▼

Use TanStack Query or SWR for client-side caching and mutations, or await fetch directly in a React Server Component. The useEffect-plus-fetch pattern has race conditions, no cache, no dedup, and no retry, so it should be replaced rather than fixed.

When should I use useReducer instead of useState?▼

Use useReducer when several values change together or the next state depends on what happened rather than the new value. The transitions become a pure function that is easy to test, while useState fits a single independently changed value.

Does React 19 still require forwardRef?▼

No. React 19 removed the need for forwardRef because ref is an ordinary prop on function components. useImperativeHandle is reached through props.ref, so the wrapper component is gone.

Why didn't my error boundary catch an error?▼

Error boundaries only catch errors during render, in lifecycle methods, and in constructors. They do not catch errors in event handlers, setTimeout callbacks, or un-awaited promises, which need their own try/catch handling.

When should I use Context versus an external store like Zustand?▼

Use Context for values that rarely change across distant branches, such as theme, auth, or locale. For frequently changing state, use an external store with selectors, because Context re-renders every consumer on every change.

Can a Client Component import a Server Component?▼

No. Importing a Server Component into a Client Component file drags it into the client bundle or fails the build. Instead, pass the Server Component as children to compose them across the boundary.