React 18/19 patterns including hooks discipline, server/client component boundaries, Suspense + error boundaries, form actions, data fetching, state manageme…
Pins this version in aipm.package.json and aipm-lock.json.
aipm add @affaan-m/react-patterns@1.0.0
Without project tracking
Writes the skill files only. Add --no-init to skip aipm.package.json and the lockfile.
aipm add @affaan-m/react-patterns@1.0.0 --no-init
How to use
Install the skill above, then run this in your AI tool:
/react-patterns <your description>
About
Idiomatic React 18/19 patterns for building robust, accessible, performant component trees.
Source
What gets added to your project
Preview every file this package writes on install before you run the command above.
Summary
React 18/19 patterns including hooks discipline, server/client component boundaries, Suspense + error boundaries, form actions, data fetching, state management decision trees, and accessibility-first composition. Use when writing or revi...
Skill instructions
React Patterns
Idiomatic React 18/19 patterns for building robust, accessible, performant component trees.
When to Activate
Writing or modifying React function components, custom hooks, or component trees
Reviewing JSX/TSX files
Designing state shape or component composition
Migrating class components or older forwardRef/useEffect-heavy code
Choosing between local state, lifted state, context, and external stores
Working with Server Components / Client Components (Next.js App Router, RSC)
Implementing forms with React 19 actions or controlled inputs
Wiring data fetching with TanStack Query / SWR / RSC
Functional updater (setX(prev => prev + 1)) when new state depends on old
Default position: do not memoize — add useMemo/useCallback only when a profiler or a dependency chain proves it matters
Extract a custom hook only when the same hook sequence appears in 2+ components
State Location Decision Tree
code
Used by one component?
-> useState inside it
Used by parent + a few descendants?
-> lift to nearest common ancestor
Used across distant branches AND low-frequency reads (theme, auth, locale)?
-> React Context
High-frequency updates shared across the tree?
-> external store (Zustand, Jotai, Redux Toolkit)
Derived from a server?
-> server-state library (TanStack Query, SWR, RSC fetch)
Most pages do not need context or a global store. Resist abstraction until duplicated lifting becomes painful.
Use controlled when the value drives other UI, formats on every keystroke, or implements real-time validation.
Complex forms
For multi-step forms, dynamic field arrays, or cross-field validation: use a library (React Hook Form, TanStack Form). Roll-your-own state management for forms past trivial complexity is a maintenance trap.
Data Fetching Decision Matrix
Need
Tool
Per-request data in Next.js App Router
RSC await fetch()
Client-side cache + mutations + invalidation
TanStack Query
Lightweight client cache + revalidation
SWR
Real-time subscriptions
Server-Sent Events, WebSockets, or the lib's subscription API
One-off fire-and-forget
fetch() in an event handler
Avoid useEffect + fetch for application data — race conditions, no cache, no retry, no Suspense integration.
This skill is router-agnostic. The patterns above work with React Router, TanStack Router, Next.js App Router, Remix Router. Router-specific patterns (loaders, actions, nested layouts) follow the router's documentation — those are framework concerns layered on top of React core.
Out of Scope (Pointer Sections)
Next.js specifics: App Router data loading, Route Handlers, Middleware, Parallel Routes — separate concern, use Next.js docs
React Native: Platform-specific patterns differ enough to warrant a separate react-native-patterns skill (not present yet)
Remix: Loader/action conventions overlap with RSC but follow Remix docs
// Two contexts: one rarely changes, one frequentlyconstThemeContext = createContext<Theme>("light");
constNotificationsContext = createContext<Notification[]>([]);
// A component that only consumes ThemeContext does NOT re-render when notifications change
Add this badge to a GitHub README so readers can open the package page and install the same version.
[](https://www.aipm-registry.com/skills/affaan-m/react-patterns/1.0.0?utm_source=github&utm_medium=readme&utm_campaign=package_badge)
This imported publisher has not claimed its AIPM account. A connected account confirms account control, but it does not guarantee that a package is safe.
AI assistant context
What this skill is for
@affaan-m/react-patterns@1.0.0 is an AIPM skill package for All tools. Use it when a project needs the reusable AI behavior described as: React 18/19 patterns including hooks discipline, server/client component boundaries, Suspense + error boundaries, form actions, data fetching, state management decision trees, and accessibility-first composition. Use when writing or revi...
Preview a UI component mockup in a local browser canvas where the human directly edits it (move, resize, edit text, delete, restyle), switches mobile/desktop/custom viewports, tests it, chats with you, and clicks Save and Finish. You the...
Run aipm add @affaan-m/react-patterns@1.0.0 in a project that has AIPM initialized.
Supported tools
@affaan-m/react-patterns@1.0.0 supports All tools.
Before installing
AIPM skills can add files to your project. Review the package name, target, description, license, and publisher before installing. Use a clean branch when trying a new skill.