1---2name: frontend-react3description: Build, maintain, and debug React frontends (TypeScript, Vite or CRA).4---56# Frontend - React78## When to use this skill9- Feature work or fixes in React apps using TypeScript.10- Creating components, routing, forms, state management, or API integration.11- Testing, linting, performance tuning, or accessibility improvements.1213## Quick start141. Install deps: `npm ci` (or project-standard package manager).152. Env: copy `.env.example` -> `.env`; set `VITE_` or `REACT_APP_` vars per stack.163. Dev: `npm run dev` (Vite) or `npm start` (CRA). Build: `npm run build`. Preview: `npm run preview` if Vite.174. Quality: `npm run lint`; tests: `npm test` or `npm run test:unit` (Vitest/Jest).1819## Project structure basics20- `src/main.tsx` or `src/index.tsx`: app bootstrap; wraps providers (router, store, query client).21- Routing: `react-router` with lazy `createBrowserRouter`/`Suspense` for code splitting.22- State: prefer React Query for server state; lightweight local state with hooks; global state with context or Zustand/Recoil as needed.23- UI components: keep props typed; avoid prop drilling via context where appropriate.2425## Coding principles26- Keep components focused; lift/share state only when necessary; type everything.27- Treat loading/error/empty states as first-class; normalize API errors.28- Use error boundaries for critical sections; ensure suspense fallbacks exist for lazy routes.29- Enforce lint/type/test/build before merge (run `scripts/dev-check.sh`).3031## Patterns and snippets32- Ready-to-use component, fetch, routing, and form patterns live in references/snippets.md.33- Centralize HTTP client (fetch/axios) for auth/error handling; prefer React Query for server state.34- Use `react-hook-form` + schema validation for forms; show per-field errors and disable submit while pending.3536## Testing37- Component tests with Testing Library; assert on user-facing behavior, not internals.38- Mock network calls; verify loading/error/success states.3940## Accessibility and UI41- Prefer semantic HTML; ensure labels for inputs; manage focus on navigation and modals.42- Support keyboard interactions; ensure color contrast; provide skip links if relevant.4344## Bundled resources45- scripts/dev-check.sh: run before commit/PR to validate lint, type-check, tests, and build using the detected package manager.46- references/coding-standards.md: quick guardrails on component sizing, typing, error states, and pre-merge checks.47- references/best-practices.md: deeper guidance for structure, routing, state, API clients, styling, testing, performance, and a11y.48- references/snippets.md: component/data-fetch/form/routing patterns ready to copy.49- assets/pr-template.md: apply when opening PRs so reviewers get scope, testing proof, and UI evidence in a consistent format.5051## Delivery checklist52- Lint, tests, and type checks pass.53- No stray console logs; env vars documented; API errors mapped to user-friendly messages.54- Routes lazy-loaded where beneficial; suspense fallbacks present; loading and empty states handled.