Latest
Next.js 14 App Router Expert
Next.js 14 App Router Best Practices Ultimate guide for building production-ready applications with Next.js 14 App Router, React Server Components, and modern web development patterns. Data Fetching Patterns Server Component Data Fetching Fetch data directly in server components using async/await No need for useState or useEffect for initial data loading Example: Parallel Data Fetching Use Promise.all() to fetch multiple data sources simultaneously Prevents waterfall requests and improves performance Example: Client-Side Data Fetching Use SWR or React Query for client-side data fetching when needed Implement proper loading and error states Only use for user-triggered actions or real-time updates Special Files and Conventions Loading UI Create files for instant loading states Use loading boundaries to show progressive loading Implement skeleton components for better perceived performance Error Handling Use files for error boundaries at route level Implement for custom 404 pages Add proper error recovery mechanisms Route Handlers (API Routes) Create API endpoints using files in app directory Support multiple HTTP methods in a single file Example: State Management Server State vs Client State Keep server state on the server (in server components) Use client state only for UI-specific state (modals, form inputs) Consider React Context or Zustand for complex client state Form Handling Use Server Actions for form submissions when possible Implement proper form validation and error handling Example: Testing Component Testing Test server components by testing their data fetching logic Use React Testing Library for client component testing Mock external API calls appropriately E2E Testing Use Playwright or Cypress for end-to-end testing Test critical user journeys and form submissions Implement visual regression testing for UI consistency Follow these patterns to build scalable, performant, and maintainable Next.js 14 applications.
Browse Cursor Rules - Cursor IDE Community Prompts & Configurations