nextjs
via PatrickJS/awesome-cursorrules
Next.js with TypeScript and Tailwind UI best practices
What is nextjs?
Enforces Next.js App Router conventions, Server Components by default, TypeScript typing, and performance optimization patterns. Use this rule when building Next.js applications to ensure consistent project structure, proper component patterns, and data-fetching strategies.
- Use App Router directory structure with lowercase-dash naming for directories
- Favor Server Components by default; mark client components explicitly with 'use client'
- Optimize images with WebP format, lazy loading, and proper sizing
- Implement Zod validation for forms with server-side error handling
- Minimize client-side state; prefer server state and React Context sparingly
- Use dynamic loading for non-critical components and implement error boundaries
Applies to
File patterns this rule matches.
Rule definition (reference)
Source of truth, from the repository.
Next.js Best Practices
Project Structure
- Use the App Router directory structure
- Place components in
appdirectory for route-specific components - Place shared components in
componentsdirectory - Place utilities and helpers in
libdirectory - 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
Related rules
Senior full-stack TypeScript, React, Node.js guidance with clean architecture, testing, and WHY-oriented reasoning.
Quantitative factor research skills for designing, evaluating, and mining alpha factors in equities markets.
Android development with Jetpack Compose, clean architecture, and Material Design 3.
Angular development with Novo Elements UI library using standalone components.
Expert Angular 18 + TypeScript development with Jest, emphasizing clean code and performance.
Manage Kubernetes clusters, add-ons, stacks, and credentials via the Ankra CLI platform.