nextjs · patrickjs — Cursor rule: what it does, how to install
This rule guides Next.js work with TypeScript and Tailwind UI. Use it when shaping project structure, components, routes, forms, and data loading.
.cursor/rules/nextjs.mdcWhat nextjs does
The rule is aimed at Next.js projects using the App Router. It directs route-specific components to app, shared components to components, and helpers to lib; directory names use lowercase kebab case. Server Components are the default, while client components must be marked with use client and placed behind Suspense with a fallback.
It covers image handling with WebP, size data, and lazy loading, plus restrained use of useEffect and setState. Data fetching should include caching, loading states, and error handling. Forms use server-side checks and Zod; routes can use dynamic and parallel patterns. The rule targets *.tsx, *.ts, src/**/*.ts, and src/**/*.tsx. Form guidance depends on Zod.
What it helps with
- organize a Next.js project around the App Router
- decide when a component should run on the server
- add loading and error states to routes
- shape data fetching with caching
- validate forms with Zod
Example prompts for the agent
- Review this screen against the Next.js App Router rules.
- Tell me whether this component needs
use clientor can stay server-rendered. - Add loading, error, and server-side validation states to this form with
Zod.
How to install nextjs
Manually: put the files in place
.cursor/rules/nextjs.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/nextjs.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/nextjs.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/nextjs.mdManually: put the files in place
.clinerules/nextjs.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about nextjs
How do I install nextjs in Cursor?
Copy the rule file to .cursor/rules/nextjs.mdc.
What does the nextjs rule do?
It sets conventions for Next.js with TypeScript and Tailwind UI, covering folders, Server Components, routing, data fetching, forms, and client state.
Which files does the nextjs rule apply to?
It applies to *.tsx, *.ts, src/**/*.ts, and src/**/*.tsx.
Source text
nextjs.mdc · CC0-1.0
--- description: "Next.js with TypeScript and Tailwind UI best practices" globs: **/*.tsx, **/*.ts, src/**/*.ts, src/**/*.tsx alwaysApply: false --- # Next.js Best Practices ## Project Structure - Use the App Router directory structure - Place components in `app` directory for route-specific components - Place shared components in `components` directory - Place utilities and helpers in `lib` directory - Use lowercase with dashes for directories (e.g., `components/auth-wizard`) ## Components - Use Server Components by default - Mark client components explicitly with 'use client' - Wrap client components in Suspense with fallback - Use dynamic loading for non-critical components - Implement proper error boundaries - Place static content and interfaces at file end ## Performance - Optimize images: Use WebP format, size data, lazy loading - Minimize use of 'useEffect' and 'setState' - Favor Server Components (RSC) where possible - Use dynamic loading for non-critical components - Implement proper caching strategies ## Data Fetching - Use Server Components for data fetching when possible - Implement proper error handling for data fetching - Use appropriate caching strategies - Handle loading and error states appropriately ## Routing - Use the App Router conventions - Implement proper loading and error states for routes - Use dynamic routes appropriately - Handle parallel routes when needed ## Forms and Validation - Use Zod for form validation - Implement proper server-side validation - Handle form errors appropriately - Show loading states during form submission ## State Management - Minimize client-side state - Use React Context sparingly - Prefer server state when possible - Implement proper loading states
© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules
Similar IDE rules
All IDE rules for Frontend and UI →nextjs by other authors comes first.