

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
1# React + TypeScript — Cursor Rules2# Comprehensive rules for modern React development with TypeScript34## Project Context5You are working on a React application written in TypeScript. The codebase uses6functional components exclusively, React 18+ features, and strict TypeScript7configuration. The goal is maintainable, type-safe, and performant UI code.89## Tech Stack10- React 18+11- TypeScript 5+ (strict mode enabled)12- Vite or Create React App (module bundler)13- React Router v6+ for routing14- CSS Modules, Tailwind, or styled-components for styling15- React Query / TanStack Query for server state16- Zustand or Context API for client state1718## Coding Style1920### Naming Conventions21- Components: PascalCase (e.g., `UserProfile`, `DashboardLayout`)22- Hooks: camelCase with `use` prefix (e.g., `useAuth`, `useFetchUsers`)23- Utilities/helpers: camelCase (e.g., `formatDate`, `parseQueryString`)24- Types/Interfaces: PascalCase with descriptive names (e.g., `UserProfile`, `ApiResponse<T>`)25- Constants: UPPER_SNAKE_CASE (e.g., `MAX_RETRY_COUNT`, `API_BASE_URL`)26- Event handlers: `handle` prefix (e.g., `handleClick`, `handleSubmit`)27- Boolean variables: `is`, `has`, `should` prefix (e.g., `isLoading`, `hasError`)28- Files: kebab-case for utilities, PascalCase for components matching component name2930### File Structure31- One component per file32- Co-locate tests: `ComponentName.test.tsx` next to `ComponentName.tsx`33- Co-locate styles: `ComponentName.module.css` next to component34- Group by feature, not by type (e.g., `features/auth/` not `components/`, `hooks/`)35- Index files only for public API of a feature module36- Shared utilities in `src/lib/` or `src/utils/`37- Shared types in `src/types/`3839## Component Patterns4041### Prefer42- Functional components with explicit return types43- Destructured props with TypeScript interfaces defined above the component44- Custom hooks to extract complex logic from components45- Composition over prop drilling — use children and render props46- Controlled components for forms47- `React.memo()` only when profiling shows re-render issues48- Named exports (not default exports) for better refactoring support49- Early returns for guard clauses in rendering logic5051### Avoid52- Class components (unless wrapping an error boundary)53- `any` type — use `unknown` and narrow with type guards54- Inline styles (use CSS modules or utility classes)55- Deeply nested ternaries in JSX — extract to variables or sub-components56- `useEffect` for derived state — compute during render instead57- Index as key in lists that can reorder58- Prop spreading (`{...props}`) without explicit typing59- Direct DOM manipulation — use refs only when necessary60- Barrel files that re-export everything (causes bundle bloat)6162## TypeScript Patterns6364### Typing Props65```tsx66interface UserCardProps {67 user: User;68 onSelect: (userId: string) => void;69 variant?: 'compact' | 'full';70 className?: string;71}7273export function UserCard({ user, onSelect, variant = 'full', className }: UserCardProps) {74 // ...75}76```7778### Typing Hooks79```tsx80function useToggle(initial = false): [boolean, () => void] {81 const [value, setValue] = useState(initial);82 const toggle = useCallback(() => setValue(v => !v), []);83 return [value, toggle];84}85```8687### Discriminated Unions for State88```tsx89type AsyncState<T> =90 | { status: 'idle' }91 | { status: 'loading' }92 | { status: 'success'; data: T }93 | { status: 'error'; error: Error };94```9596### Generic Components97```tsx98interface ListProps<T> {99 items: T[];100 renderItem: (item: T) => React.ReactNode;101 keyExtractor: (item: T) => string;102}103```104105## Error Handling106- Use Error Boundaries for component tree errors107- Handle async errors in try/catch within hooks or query error callbacks108- Display user-friendly error messages, log detailed errors to console/service109- Use `ErrorBoundary` wrapper components per feature area, not one global boundary110- Type error states explicitly in component state111112## Testing Requirements113- Test behavior, not implementation details114- Use React Testing Library (not Enzyme)115- Test user interactions: click, type, submit116- Test conditional rendering logic117- Mock API calls at the network level (MSW preferred)118- Aim for integration tests over unit tests for components119- Unit test complex hooks and utility functions independently120- Name tests descriptively: `it('shows error message when submission fails')`121122## Performance Guidelines123- Use `React.lazy()` and `Suspense` for route-level code splitting124- Memoize expensive computations with `useMemo` (only after profiling)125- Stabilize callback references with `useCallback` when passed to memoized children126- Virtualize long lists (react-window or react-virtuoso)127- Avoid creating new objects/arrays in render — lift to constants or useMemo128- Use React DevTools Profiler before optimizing129130## Common Pitfalls131- Forgetting dependency arrays in useEffect/useMemo/useCallback132- Setting state in useEffect that triggers infinite re-renders133- Not cleaning up subscriptions/timers in useEffect return134- Using `useEffect` to sync props to state (derive instead)135- Mutating state directly instead of creating new references136- Over-fetching data — use pagination or infinite scroll137- Not handling loading and error states in async operations138- Ignoring accessibility (see accessibility-a11y.cursorrules for full guide)139
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| survivorforge/cursor-rulesrules/ai-ml-python/.cursorrules · 16 | .cursorrules | teststylearchdeployment+2 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/langchain-ai/.cursorrules · 16 | .cursorrules | testlint-formatstylearch+4 | 84/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/aws-serverless/.cursorrules · 16 | .cursorrules | teststylearchtypes+6 | 73/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/tailwindcss/.cursorrules · 16 | .cursorrules | lint-formatstylearchui+3 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/mern-stack/.cursorrules · 16 | .cursorrules | setupteststylearch+6 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/api-design-rest/.cursorrules · 16 | .cursorrules | lint-formatstylesecurityapi+3 | 69/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/api-microservices/.cursorrules · 16 | .cursorrules | buildteststylearch+5 | 92/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/chrome-extension/.cursorrules · 16 | .cursorrules | teststylearchtesting-strategy+4 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/clean-code/.cursorrules · 16 | .cursorrules | styledo-notagent-behaviourdocs | 57/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/database-sql/.cursorrules · 16 | .cursorrules | styletypessecuritydatabase+3 | 65/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/devops-docker/.cursorrules · 16 | .cursorrules | setupbuildteststyle+4 | 93/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/devops-infrastructure/.cursorrules · 16 | .cursorrules | buildteststylesecurity+3 | 93/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/django-rest/.cursorrules · 16 | .cursorrules | buildteststylearch+5 | 84/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/docker-devops/.cursorrules · 16 | .cursorrules | setupteststylearch+6 | 85/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/flutter-dart/.cursorrules · 16 | .cursorrules | teststylearchtypes+5 | 89/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/fullstack-nextjs-prisma/.cursorrules · 16 | .cursorrules | teststylearchtypes+7 | 96/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/go-gin/.cursorrules · 16 | .cursorrules | testlint-formatstylearch+5 | 84/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/mobile-react-native/.cursorrules · 16 | .cursorrules | teststylearchtypes+7 | 89/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/nextjs-14-app-router/.cursorrules · 16 | .cursorrules | teststyletypestesting-strategy+3 | 71/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/nextjs-app-router/.cursorrules · 16 | .cursorrules | teststylearchtypes+5 | 81/100 | 13 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/survivorforge-cursor-rules-rules-react-typescript-cursorrules)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.