Best .cursorrules for React & Next.js Developers 2026
Production-ready .cursorrules for React 18 and Next.js 15. Copy, paste, and start getting better AI-generated code immediately.
How to use these
Copy a ruleset below into .cursorrules in your project root (or .cursor/rules/react.md for named rules). Restart Cursor. Your AI now applies React and Next.js best practices automatically.
Generic Cursor rules give generic results. React and Next.js have specific patterns — App Router vs Pages Router, Server vs Client Components, React 18 hooks — that a general AI assistant doesn't know about your project.
These rules teach your AI assistant the right patterns for your exact stack.
React 18 Expert
Core React 18 rules covering hooks, state management, and component patterns.
Add to .cursorrules:
You are an expert React 18 developer. Follow these rules: COMPONENTS: - Use functional components with TypeScript interfaces for props - Keep components small and focused (< 100 lines as a guideline) - Extract logic into custom hooks when it involves state + effects - Prefer composition over prop drilling — use React Context for shared state - Add displayName to forwardRef components for better debugging HOOKS: - Always specify dependencies in useEffect/useMemo/useCallback - Use useCallback for event handlers passed as props - Never call hooks inside conditions, loops, or nested functions - Use useId for generating stable IDs (not Math.random()) - Prefer useDeferredValue for expensive derived state STATE: - Keep state as close to where it's used as possible (colocation) - Use useReducer for complex state with multiple actions - Never mutate state directly — always create new objects/arrays - Batch related state updates into a single setState call PERFORMANCE: - Use React.memo() for components that re-render with same props - Virtualize long lists (react-virtual or react-window) - Lazy load components with React.lazy() + Suspense - Avoid object/array literals in JSX (they create new references each render)
Next.js 15 App Router
Server Components, data fetching, and App Router patterns for Next.js 15.
Add to .cursorrules:
You are an expert Next.js 15 developer using the App Router.
SERVER vs CLIENT COMPONENTS:
- Default to Server Components — only add 'use client' when needed
- Use 'use client' for: event handlers, useState, useEffect, browser APIs
- Never import Server Component into Client Component (pass as children prop)
- Use server actions for form mutations (not API routes for simple mutations)
DATA FETCHING:
- Fetch in Server Components, not useEffect
- Use fetch() with proper cache options: { cache: 'no-store' } or { next: { revalidate: 3600 } }
- Use React Suspense boundaries for loading states
- Use generateStaticParams for dynamic routes you can statically generate
ROUTING & LAYOUT:
- Use layout.tsx for shared UI (headers, sidebars)
- Use loading.tsx for Suspense boundaries at route level
- Use error.tsx for error boundaries
- Use not-found.tsx for 404 handling
- Group related routes with (groupName) folders
OPTIMIZATION:
- Use next/image for ALL images (auto optimization, lazy loading)
- Use next/font for ALL fonts (no FOUT)
- Use next/link for ALL internal navigation
- Prefer generateMetadata over static metadata for dynamic pagesNext.js Full Stack (Recommended)
Complete rules for full-stack Next.js with TypeScript, Tailwind, and Supabase/Prisma.
Add to .cursorrules:
You are a senior full-stack Next.js 15 developer. This is an App Router project with TypeScript, Tailwind CSS, and shadcn/ui. ARCHITECTURE: - Use App Router — no /pages directory - Server Components by default, 'use client' only when needed - co-locate files: page.tsx, layout.tsx, loading.tsx, error.tsx in feature folders - API routes in /app/api/ for external integrations only; prefer server actions for mutations TYPESCRIPT: - Strict mode — never use 'any' - Define types in /types/ or co-located with feature - Use zod for runtime validation at API boundaries - Return types on all API functions STYLING: - Tailwind utility classes only — no custom CSS unless absolutely necessary - Use shadcn/ui components from /components/ui/ - Use cn() utility for conditional class merging - Responsive-first: mobile styles default, md: for tablet, lg: for desktop DATABASE (adapt to project stack): - Always use the service layer, never raw DB calls in components - Use server-side only for DB — never expose credentials to client - Validate and sanitize all inputs before DB writes FORMS: - Use React Hook Form + Zod for form validation - Use server actions for form submission - Show loading state, success, and error states SECURITY: - Authenticate in middleware or server action — never trust client - Use environment variables for secrets (never hardcode) - CSRF protection for all state-changing endpoints
Tips for Writing Your Own React/Next.js Rules
- Be specific about your version — "Next.js 15 App Router" vs "Next.js" gives much better results
- Include your stack — "using shadcn/ui, Tailwind CSS, and Supabase" prevents the AI from suggesting alternatives
- List anti-patterns — "Never use getServerSideProps" or "Never use useEffect for data fetching" is more actionable than "use best practices"
- Add your naming conventions — "Components in PascalCase, hooks in useCamelCase, utilities in camelCase"
Frequently Asked Questions
Should I use .cursorrules or SKILL.md for React rules?
Use .cursorrules for Cursor-specific rules. Use SKILL.md if you also use Claude Code. The content can be identical — just the file format differs slightly.
Do these rules work with Next.js Pages Router?
The App Router rules above are for Next.js 13+ App Router. If you're on Pages Router, remove the Server Component rules and replace with getServerSideProps / getStaticProps patterns.
Can I combine multiple rulesets?
Yes — combine the React 18 rules with the Next.js Full Stack rules. Just watch for contradictions and keep the total length under ~2,000 tokens for best results.
Want Python Rules Too?
See our Python .cursorrules guide, or check the full cursorrules reference.