agentleFS
seandkendallseandkendall/kiro-config/skills/react-frontend-patterns/SKILL.md

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.

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
  1. Distinctive:

    Never prop-drill more than 2 levels

    line 73
  2. Distinctive:

    All interactive elements keyboard-reachable (Tab, Enter, Space, Escape)

    line 77
  3. Very specific:

    All images have alt text (decorative: alt="")

    line 80
  4. Very specific:

    NEVER use browser alert(), confirm(), or prompt() dialogs — for ANY purpose: informational messages, error/success notifications, …

    line 83
  5. Very specific:

    Every <button> / <a> (clickable)

    line 101
  6. Very specific:

    Every <input> / <select> / <textarea> (user input)

    line 102
  7. Very specific:

    Every <form> (submission target)

    line 103
  8. Distinctive:

    Every page-level container (test entry point)

    line 104
  9. Distinctive:

    Every error/success message (assertion target)

    line 105
  10. Distinctive:

    Every modal / dialog (visibility check)

    line 106
  11. Distinctive:

    Every loading indicator (race-condition guard)

    line 107
  12. Very specific:

    Never use class selectors, IDs, or tag selectors in Playwright — page.getByTestId('...') only

    line 123
  13. Distinctive:

    Keep selectors stable — only change them when the element's purpose changes, not when styles or DOM hierarchy change

    line 124
  14. Very specific:

    Avoid dynamic IDs like data-testid="btn-${randomId}" — use stable entity identifiers

    line 125

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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: none without replacement
  • Color contrast: 4.5:1 normal text, 3:1 large text
  • All images have alt text (decorative: alt="")
  • Form inputs have <label> or aria-label
  • Error messages use role="alert"
  • NEVER use browser alert(), confirm(), or prompt() dialogs — for ANY purpose: informational messages, error/success notifications, confirmations, or approval prompts. Always use a modal component instead (shadcn/ui Dialog for messages/notifications, AlertDialog for 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>"

ElementPatternExample
Submit button<entity>-submitdata-testid="invoice-submit"
Cancel button<entity>-canceldata-testid="invoice-cancel"
Form input<entity>-<field>-inputdata-testid="invoice-amount-input"
Error message<entity>-errordata-testid="invoice-error"
Page container<page>-pagedata-testid="dashboard-page"
List item<entity>-row-<id>data-testid="invoice-row-123"
Modal<entity>-modaldata-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-testid per 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.