react
π―SkillInstallation
npx skills add g1joshi/agent-skills --skill reactRun it in a terminal; it asks which AI coding tools to install it for (Claude Code, Codex, Cursor and more).
Uses skills.sh Β· Node.js 22.20+
After installing
Ask for related work and the agent uses it on its own, or call it yourself.
/reactInstall by hand
Copy the whole skill folder from GitHub to the place below. Copying only SKILL.md can leave out files the skill uses.
Open the skill folder β- This project
.claude/skills/react/ - All projects
~/.claude/skills/react/
These paths are for Claude Code. For other tools, the command above puts it in the right place.
SKILL.md
View on GitHub βExpert React assistance covering React 19, Server Components (RSC), hooks, compiler optimizations, and concurrent features. Use when building modern web user interfaces and single-page apps.
React
React is the standard library for building declarative user interfaces, featuring the React Compiler, Server Components, concurrent rendering, and native Actions.
When to Use
- Single Page Apps (SPA): Rich, interactive dashboards.
- Complex UI: Applications with many moving parts and state.
- Ecosystem: When you need the largest library of 3rd party components.
Quick Start
import { use, Suspense } from "react";
// New: 'use' hook for promises
function Comments({ commentsPromise }) {
const comments = use(commentsPromise);
return comments.map((c) => <p key={c.id}>{c.text}</p>);
}
export default function Page({ id }) {
const commentsPromise = fetchComments(id);
return (
<Suspense fallback={<p>Loading...</p>}>
<Comments commentsPromise={commentsPromise} />
</Suspense>
);
}
Core Concepts
React Compiler
React 19 introduces an auto-memoizing compiler. You no longer need useMemo or useCallback manually in 99% of cases. The compiler treats code as "memoized by default".
Server Components (RSC)
Components that run only on the server. They don't send JS to the client.
'use server': Marks a function as a Server Action (callable from client).'use client': Marks a component as interactive (hydrated on client).
Actions and useActionState
Native support for async form submission.
function Form() {
const [error, submitAction, isPending] = useActionState(
async (prev, formData) => {
const error = await updateProfile(formData);
if (error) return error;
return null;
},
null,
);
return (
<form action={submitAction}>
<input name="name" />
<button disabled={isPending}>Save</button>
{error && <p>{error}</p>}
</form>
);
}
Common Patterns
Custom Reusable Hook with Cleanup
Problem: Duplicating event listeners or subscription lifecycles across UI components.
Solution: Encapsulate logic in a typed custom hook:
import { useState, useEffect } from "react";
export function useWindowWidth() {
const [width, setWidth] = useState(() =>
typeof window !== "undefined" ? window.innerWidth : 1024,
);
useEffect(() => {
const handleResize = () => setWidth(window.innerWidth);
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, []);
return width;
}
Best Practices
Do:
- Trust the Compiler: Stop writing
useMemo/useCallbackunless you are building a library or strictly optimizing. - Use Server Actions: Replace manual
fetch('/api/...')with robust Server Actions for data mutations. - Use
refas a prop: In React 19,refis a plain prop. No moreforwardRef.
Don't:
- Overuse
useEffect: Effects are for synchronization with external systems, not for data fetching or derived state. - Spread props blindly: Pass explicit props to make components easier to debug.
Troubleshooting
| Error | Cause | Solution |
|---|---|---|
Too many re-renders. React limits the number of renders to prevent an infinite loop | State setter invoked directly in component body instead of handler/useEffect. | Wrap setter call inside an event handler or useEffect: () => setCount(c + 1). |
Rendered fewer hooks than expected | Hook called inside a conditional if statement or loop. | Always call React hooks at the top level of component before conditionals. |
Hydration mismatch: Text content does not match server-rendered HTML | Client-only values evaluated during initial server render. | Use suppressHydrationWarning on element or load after mount. |
References
More from this repository10
A template skill providing a starter framework for creating new agent skills with structured sections for triggers, quick start examples, and capability descriptions.
Skill
Skill
Skill
Skill
Skill
Skill
Skill
Skill
Skill