react-frontend-patterns
Skill8 starsChanged 41 days agoApache-2.0View on GitHub
React 19+, TypeScript, Tailwind CSS, shadcn/ui component patterns, accessibility, forms, state management. Use when building or reviewing React components, pages, or frontend architecture.
In this repository17 other files it gives its agents.
- AGENTSAGENTS.md
- amazon-bedrockSkill
- amazon-location-serviceSkill
- amazon-polly-generativeSkill
- aws-architecture-diagramSkill
- aws-diagram-htmlSkill
- aws-diagram-pngSkill
- aws-serverless-patternsSkill
- cdk-infrastructure-patternsSkill
- cognito-email-migrationSkill
- cognito-passkey-authSkill
- deploy-on-awsSkill
- email-template-renderingSkill
- mcp-tool-discoverySkill
- personal-rules-managementSkill
- reinvent-stack-toolkitSkill
- testing-patternsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 7 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 73
Never prop-drill more than 2 levels
- Distinctive: line 77
All interactive elements keyboard-reachable (Tab, Enter, Space, Escape)
- Very specific: line 80
All images have alt text (decorative: alt="")
- Very specific: line 83
NEVER use browser alert(), confirm(), or prompt() dialogs — for ANY purpose: informational messages, error/success notifications, …
- Very specific: line 101
Every <button> / <a> (clickable)
- Very specific: line 102
Every <input> / <select> / <textarea> (user input)
- Very specific: line 103
Every <form> (submission target)
- Distinctive: line 104
Every page-level container (test entry point)
- Distinctive: line 105
Every error/success message (assertion target)
- Distinctive: line 106
Every modal / dialog (visibility check)
- Distinctive: line 107
Every loading indicator (race-condition guard)
- Very specific: line 123
Never use class selectors, IDs, or tag selectors in Playwright — page.getByTestId('...') only
- Distinctive: line 124
Keep selectors stable — only change them when the element's purpose changes, not when styles or DOM hierarchy change
- Very specific: line 125
Avoid dynamic IDs like data-testid="btn-${randomId}" — use stable entity identifiers
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
React Frontend Patterns
Component Template
/** Dashboard page — displays financial overview with charts and recent transactions. */
interface DashboardProps {
userId: string;
}
export function Dashboard({ userId }: DashboardProps) {
const { data, isLoading, error } = useQuery({
queryKey: ['dashboard', userId],
queryFn: fetchDashboard,
});
if (isLoading) return <DashboardSkeleton />;
if (error) return <ErrorState message="Failed to load dashboard" />;
if (!data) return <EmptyState message="No data yet" />;
return (
<main data-testid="dashboard-page">
<h1 className="text-2xl font-bold">Dashboard</h1>
{/* content */}
</main>
);
}Form Pattern (react-hook-form + zod)
const schema = z.object({
amount: z.number().positive('Must be greater than 0'),
description: z.string().min(1, 'Required'),
});
function TransactionForm() {
const {
register,
handleSubmit,
formState: { errors },
} = useForm({ resolver: zodResolver(schema) });
return (
<form onSubmit={handleSubmit(onSubmit)} data-testid="transaction-form">
<label htmlFor="amount">Amount</label>
<input
id="amount"
type="number"
aria-invalid={!!errors.amount}
aria-describedby="amount-error"
{...register('amount', { valueAsNumber: true })}
/>
{errors.amount && (
<p id="amount-error" role="alert">
{errors.amount.message}
</p>
)}
</form>
);
}State Management
- Server state: TanStack Query (useQuery, useMutation, optimistic updates)
- Client state: Zustand for global UI state, React Context for theme/auth
- Never prop-drill more than 2 levels
Accessibility Checklist
- All interactive elements keyboard-reachable (Tab, Enter, Space, Escape)
- Visible focus indicators — never
outline: nonewithout replacement - Color contrast: 4.5:1 normal text, 3:1 large text
- All images have
alttext (decorative:alt="") - Form inputs have
<label>oraria-label - Error messages use
role="alert" - NEVER use browser
alert(),confirm(), orprompt()dialogs — for ANY purpose: informational messages, error/success notifications, confirmations, or approval prompts. Always use a modal component instead (shadcn/uiDialogfor messages/notifications,AlertDialogfor confirmations/approvals that block on a user decision)
Responsive Breakpoints
Four tiers, covering phones through TV/dashboard displays (kept in sync with tech.md and accessibility-standards.md):
- Mobile (phones): 375px (default, mobile-first)
- Tablet / small laptop:
md:(768px) - Desktop / widescreen:
lg:(1280px) - TV / dashboard (large displays, kiosks, car dashboards):
2xl:(1920px) - Touch targets: minimum 44x44px on mobile
data-testid Selectors (MANDATORY — for Playwright)
data-testid attributes are REQUIRED on every interactive element. Playwright tests are non-negotiable in this codebase, and CSS/class selectors break tests when styles change.
Required on:
- Every
<button>/<a>(clickable) - Every
<input>/<select>/<textarea>(user input) - Every
<form>(submission target) - Every page-level container (test entry point)
- Every error/success message (assertion target)
- Every modal / dialog (visibility check)
- Every loading indicator (race-condition guard)
Naming pattern: data-testid="<entity>-<action>" or data-testid="<entity>-<role>"
| Element | Pattern | Example |
| Submit button | <entity>-submit | data-testid="invoice-submit" |
| Cancel button | <entity>-cancel | data-testid="invoice-cancel" |
| Form input | <entity>-<field>-input | data-testid="invoice-amount-input" |
| Error message | <entity>-error | data-testid="invoice-error" |
| Page container | <page>-page | data-testid="dashboard-page" |
| List item | <entity>-row-<id> | data-testid="invoice-row-123" |
| Modal | <entity>-modal | data-testid="delete-confirm-modal" |
Rules:
- Never use class selectors, IDs, or tag selectors in Playwright —
page.getByTestId('...')only - Keep selectors stable — only change them when the element's purpose changes, not when styles or DOM hierarchy change
- Avoid dynamic IDs like
data-testid="btn-${randomId}"— use stable entity identifiers - One
data-testidper element — don't reuse the same value on multiple elements (Playwright will throw a strict-mode violation) - For lists, include the row's unique identifier so individual rows can be selected
Code review enforcement: PRs that add interactive elements WITHOUT data-testid selectors should be rejected. The testing agent will flag missing selectors automatically when it sees a component without coverage.
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.

