react-patterns
Skill8 starsChanged 2 months agoMITView on GitHub
React best practices covering functional components, hooks, state management, performance, and accessibility. Use when writing or reviewing React components, hooks, or state logic.
38 other projects use a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- lhbsaa/apex-unifiedtheir own version, first seen Nov 8, 2026
- reddygopalkrishna/developer-agent-skillstheir own version, first seen Nov 8, 2026
- komluk/scaffoldingtheir own version, first seen Nov 7, 2026
- Lukk17/agent-standardstheir own version, first seen Nov 7, 2026
- ku5ic/claude-kittheir own version, first seen Nov 4, 2026
- renepf/claude-skillstheir own version, first seen Oct 25, 2026
Used with
Projects with it also use typescript-patterns, docker-expert and 7 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
cohen-lielSkilltypescript-patterns
TypeScript best practices and patterns. Use when writing TypeScript code, defining types, working with generics, or converting JavaScript to TypeScript.
Also in 3 projects that use this
xfstudioSkilldocker-expert
Docker containerization expert with deep knowledge of multi-stage builds, image optimization, container security, Docker Compose orchestration, and production deployment patterns. Use PROACTIVELY for Dockerfile optimization, container issues, image size problems, security hardening, networking, and orchestration challenges.
Also in 3 projects that use this
LangChainSkilldocker-patterns
Best practices for Docker containerization and multi-stage builds
Also in 4 projects that use this
LangChainSkilldatabase-migrations
Database migration patterns and schema versioning
Also in 4 projects that use this
MicrosoftSkillerror-handling
统一错误处理系统。在添加 API 端点、修改错误处理、添加前端 API 调用、编写错误相关测试时使用。
Also in 5 projects that use this
HABUBUSSSkillbackend-patterns
Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.
Also in 5 projects that use this
Other versions38 projects use a version of this.
Word for word · 0
None found.
Edited · 1
- halflength-ampleness75/claude-code-recipes★ 2100% same
Wrote their own version · 37
- openstory-so/openstory★ 696same name
- involvex/youtube-music-cli★ 477same name
- xenitV1/Antigravity-Workflows★ 130same name
- TangleML/tangle-ui★ 104same name
- maxyeh0817/Forge★ 34same name
- VoDaiLocz/kilo-kit-mcp★ 28same name
- Fandry96/k3-agentic-skills★ 27same name
- komluk/scaffolding★ 16same name
- xfstudio/skills★ 9same name
- gongyijie85/dsh-ecc★ 8same name
27 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository5 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- api-designSkill
- git-workflowSkill
- testing-strategySkill
- typescript-strictSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.
0
Common
Most of the 34 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 88
Use the simplest tier that solves the problem:
“Common” is measured: kept by at least 6 in 10 of the 34 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
React Patterns
Best practices for React development: functional components, hooks, state management, performance, and accessibility.
Component Rules
- Always use functional components -- never class components for new code
- One component per file -- name the file the same as the component (PascalCase)
- Export components as named exports -- default exports only for pages/routes
- Colocate related files -- keep
Component.tsx,Component.test.tsx, andComponent.module.csstogether - Props interface above the component -- name it
ComponentNameProps
// Good
interface UserCardProps {
user: User;
onSelect: (id: string) => void;
variant?: "compact" | "full";
}
export function UserCard({ user, onSelect, variant = "full" }: UserCardProps) {
return ( /* ... */ );
}// Bad -- default export, inline props, class component
export default class UserCard extends React.Component<{user: any}> { /* ... */ }Hooks Patterns
Custom Hooks
- Prefix with
use--useAuth,useDebounce,useLocalStorage - Extract shared logic into custom hooks -- if two components share stateful logic, extract it
- Return tuples for simple hooks, objects for complex ones
// Simple: return tuple
function useToggle(initial = false): [boolean, () => void] {
const [value, setValue] = useState(initial);
const toggle = useCallback(() => setValue((v) => !v), []);
return [value, toggle];
}
// Complex: return object
function useApi<T>(url: string) {
const [data, setData] = useState<T | null>(null);
const [error, setError] = useState<Error | null>(null);
const [loading, setLoading] = useState(true);
// ... fetch logic
return { data, error, loading, refetch };
}Hook Rules
- Never call hooks conditionally -- all hooks must run on every render
- Use
useCallbackfor functions passed to children -- prevents unnecessary re-renders - Use
useMemoonly for expensive computations -- don't wrap everything - Prefer
useReduceroveruseStatewhen state transitions are complex
useEffect Guidelines
- Always specify dependencies -- never use
// eslint-disable-next-line - Return a cleanup function for subscriptions, timers, and listeners
- Avoid setting state in useEffect when you can derive it -- computed values don't need effects
// Bad -- unnecessary effect
const [fullName, setFullName] = useState("");
useEffect(() => {
setFullName(`${firstName} ${lastName}`);
}, [firstName, lastName]);
// Good -- derived value
const fullName = `${firstName} ${lastName}`;State Management Tiers
Use the simplest tier that solves the problem:
| Tier | Tool | When to Use |
| 1. Local state | useState, useReducer | Single component state |
| 2. Lifted state | Props, composition | Shared between parent/child |
| 3. Context | createContext + useContext | Theme, auth, locale -- rarely changes |
| 4. URL state | Search params, path params | Filters, pagination, navigation state |
| 5. Server state | React Query / SWR | API data, caching, synchronization |
| 6. Global store | Zustand / Redux Toolkit | Complex client state across many components |
Context Guidelines
- Split contexts by domain --
AuthContext,ThemeContext, notAppContext - Keep context values stable -- use
useMemoon the provider value - Don't put frequently changing values in context -- it re-renders all consumers
// Good -- stable context value
function AuthProvider({ children }: { children: ReactNode }) {
const [user, setUser] = useState<User | null>(null);
const value = useMemo(() => ({ user, setUser }), [user]);
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
}Performance
- Use React.lazy + Suspense for route-level code splitting
- Memoize expensive list items with
React.memo-- include a custom comparator if props are objects - Virtualize long lists -- use
react-windowor@tanstack/virtualfor 100+ items - Avoid anonymous functions in JSX when passing to memoized children
- Use
keycorrectly -- stable, unique identifiers, never array index for dynamic lists
// Good -- code splitting
const Dashboard = lazy(() => import("./pages/Dashboard"));
function App() {
return (
<Suspense fallback={<Loading />}>
<Routes>
<Route path="/dashboard" element={<Dashboard />} />
</Routes>
</Suspense>
);
}Accessibility
- Use semantic HTML --
<button>not<div onClick>,<nav>not<div className="nav"> - All images need alt text -- empty
alt=""for decorative images - Form inputs need labels -- use
<label htmlFor>oraria-label - Manage focus on route changes -- focus the main heading after navigation
- Support keyboard navigation -- all interactive elements must be reachable via Tab
- Use ARIA attributes when semantic HTML is insufficient --
aria-expanded,aria-live,role
// Good -- accessible modal
function Modal({ isOpen, onClose, title, children }: ModalProps) {
const closeRef = useRef<HTMLButtonElement>(null);
useEffect(() => {
if (isOpen) closeRef.current?.focus();
}, [isOpen]);
if (!isOpen) return null;
return (
<div role="dialog" aria-modal="true" aria-labelledby="modal-title">
<h2 id="modal-title">{title}</h2>
{children}
<button ref={closeRef} onClick={onClose}>
Close
</button>
</div>
);
}Error Boundaries
- Wrap route-level components in error boundaries
- Provide a meaningful fallback UI -- not just "Something went wrong"
- Log errors to your monitoring service in the boundary
import { ErrorBoundary } from "react-error-boundary";
function ErrorFallback({ error, resetErrorBoundary }: FallbackProps) {
return (
<div role="alert">
<h2>Something went wrong</h2>
<pre>{error.message}</pre>
<button onClick={resetErrorBoundary}>Try again</button>
</div>
);
}
// Usage
<ErrorBoundary FallbackComponent={ErrorFallback}>
<Dashboard />
</ErrorBoundary>Anti-patterns
- Prop drilling more than 2 levels -- use composition or context instead
- Giant useEffect blocks -- split into multiple focused effects
- Storing derived state -- compute it during render
- Premature optimization -- profile before adding
useMemo/useCallbackeverywhere - String-based refs -- use
useRefonly - Direct DOM manipulation -- use refs only when React APIs are insufficient
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

