Loading...
Loading...
React 19+ patterns, performance optimization, and component architecture. Covers hooks, state management decision trees, data fetching with use() API, Server Components, React Compiler, bundle optimization, and re-render elimination. Use when building components, optimizing re-renders, fetching data, managing state, handling forms, structuring frontends, or reviewing React code.
npx skill4agent add oakoss/agent-skills react-patterns| Pattern | API / Approach | Key Points |
|---|---|---|
| Data fetching | | Replaces useEffect+useState fetch pattern |
| Form handling | | Built-in pending states and error handling |
| Optimistic UI | | Instant feedback while server processes |
| Non-urgent updates | | Mark updates as interruptible |
| Effect events | | Reactive values without re-triggering effects |
| Form pending status | | Read parent form pending state from child component |
| Unique IDs | | Hydration-safe IDs for accessibility |
| Server state | React Query / | Caching, deduplication, background refetch |
| Client state (local) | | Single component or transient values |
| Client state (global) | Zustand / Context | Cross-component client-only state |
| Derived state | Compute during render | Never sync derived values with effects |
| Lazy initialization | | Avoid eager computation on every render |
| Component types | Page, Feature, UI | Route entry, business logic, reusable primitives |
| Memoization | Trust React Compiler first | Manual useMemo/useCallback only when needed |
| Ref as prop | | No |
| Ref cleanup | Return function from ref callback | Cleanup runs on detach instead of |
| Code splitting | | Lazy-load heavy components |
| Parallel fetches | | Eliminate sequential await waterfalls |
| Request dedup | | Per-request server-side deduplication |
| Abort server work | | Cancel expensive async work when client disconnects |
| State preservation | | Hide UI while keeping state mounted |
| Mistake | Correct Pattern |
|---|---|
| Fetching data in useEffect with useState | Use the |
| Storing derived values in state and syncing with effects | Compute derived values during render; never use effects for state synchronization |
| Wrapping everything in useMemo and useCallback | Trust React Compiler first; only add manual memoization for expensive computations or memoized children |
Using | Use |
Using | Use ternary |
| Using Math.random() or Date for IDs | Use |
| Putting reactive values in effect deps to read latest value | Use |
| Creating object literals as effect dependencies | Hoist static objects outside the component or use primitive dependencies |
Using | Pass |
| Mutating props or state during render | Follow Rules of React for React Compiler compatibility: pure renders, no side effects |
ExploreTaskPlan