Skip to main content
rule

nextjs-react-typescript-cursorrules-prompt-file — Cursor rule

A Cursor rule that tells the agent how to write code in Next.js 14 App Router, React and TypeScript projects.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/nextjs-react-typescript-cursorrules-prompt-file.mdc
Open on GitHub

What nextjs-react-typescript-cursorrules-prompt-file does

The file sets coding conventions: functional components, declarative JSX, interfaces over types, named exports, and the RORO pattern. A separate section covers error handling — early returns, guard clauses, happy path last in the function. Another one is about React and Next.js: keep use client and useEffect to a minimum, lean on server components, validate forms with Zod, and route server actions through next-safe-action with an ActionResponse type.

Project conventions are listed too: rely on the App Router for state changes, watch Web Vitals, build UI with Shadcn UI, Radix and Tailwind Aria, serve images as WebP with lazy loading. Directories use lowercase with dashes, static content and interfaces go at the end of the file.

The rule ships with alwaysApply: false and globs **/*, so it is not attached to every file by default — worth checking how your Cursor picks up .mdc files, or the agent never sees the instructions. The header also claims Solidity, Viem and Wagmi expertise, which is extra context for a plain frontend project.

What it helps with

  • keep the agent on one coding style across a Next.js project
  • move components to the server and drop unnecessary use client
  • make server actions type-safe with next-safe-action
  • structure error handling around early returns instead of nested conditions
  • lock down file and folder layout so the agent stops inventing its own

Example prompts for the agent

  • Generate a form component following the project rules, with Zod validation and useActionState
  • Rewrite this component as a server component, keep use client only where Web API access is needed
  • Add a server action with next-safe-action that returns the ActionResponse type

How to install nextjs-react-typescript-cursorrules-prompt-file

Manually: put the files in place

.cursor/rules/nextjs-react-typescript-cursorrules-prompt-file.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about nextjs-react-typescript-cursorrules-prompt-file

How do I install nextjs-react-typescript-cursorrules-prompt-file in Cursor?

Create the file .cursor/rules/nextjs-react-typescript-cursorrules-prompt-file.mdc and paste the rule content into it.

What does this rule do?

It gives the Cursor agent a coding style for Next.js 14 App Router, React and TypeScript: functional components, interfaces over types, early returns for errors, minimal use client.

Does the rule apply to every file automatically?

It declares alwaysApply: false with globs **/*, so whether it kicks in depends on how Cursor handles .mdc files in your project.

Source text

nextjs-react-typescript-cursorrules-prompt-file.mdc · CC0-1.0
---
description: "Cursor rules for Next.js development with React and TypeScript integration."
globs: **/*
alwaysApply: false
---
You are an expert in Solidity, TypeScript, Node.js, Next.js 14 App Router, React, Vite, Viem v2, Wagmi v2, Shadcn UI, Radix UI, and Tailwind Aria.  

Key Principles

- Write concise, technical responses with accurate TypeScript examples.
- Use functional, declarative programming. Avoid classes.
- Prefer iteration and modularization over duplication.
- Use descriptive variable names with auxiliary verbs (e.g., isLoading).
- Use lowercase with dashes for directories (e.g., components/auth-wizard).
- Favor named exports for components.
- Use the Receive an Object, Return an Object (RORO) pattern.  

JavaScript/TypeScript

- Use "function" keyword for pure functions. Omit semicolons.
- Use TypeScript for all code. Prefer interfaces over types. Avoid enums, use maps.
- File structure: Exported component, subcomponents, helpers, static content, types.
- Avoid unnecessary curly braces in conditional statements.
- For single-line statements in conditionals, omit curly braces.
- Use concise, one-line syntax for simple conditional statements (e.g., if (condition) doSomething()).  

Error Handling and Validation

- Prioritize error handling and edge cases:
  - Handle errors and edge cases at the beginning of functions.
  - Use early returns for error conditions to avoid deeply nested if statements.
  - Place the happy path last in the function for improved readability.
  - Avoid unnecessary else statements; use if-return pattern instead.
  - Use guard clauses to handle preconditions and invalid states early.
  - Implement proper error logging and user-friendly error messages.
  - Consider using custom error types or error factories for consistent error handling.  

React/Next.js

- Use functional components and TypeScript interfaces.
- Use declarative JSX.
- Use function, not const, for components.
- Use Shadcn UI, Radix, and Tailwind Aria for components and styling.
- Implement responsive design with Tailwind CSS.
- Use mobile-first approach for responsive design.
- Place static content and interfaces at file end.
- Use content variables for static content outside render functions.
- Minimize 'use client', 'useEffect', and 'setState'. Favor RSC.
- Use Zod for form validation.
- Wrap client components in Suspense with fallback.
- Use dynamic loading for non-critical components.
- Optimize images: WebP format, size data, lazy loading.
- Model expected errors as return values: Avoid using try/catch for expected errors in Server Actions. Use useActionState to manage these errors and return them to the client.
- Use error boundaries for unexpected errors: Implement error boundaries using error.tsx and global-error.tsx files to handle unexpected errors and provide a fallback UI.
- Use useActionState with react-hook-form for form validation.
- Code in services/ dir always throw user-friendly errors that tanStackQuery can catch and show to the user.
- Use next-safe-action for all server actions:
  - Implement type-safe server actions with proper validation.
  - Utilize the action function from next-safe-action for creating actions.
  - Define input schemas using Zod for robust type checking and validation.
  - Handle errors gracefully and return appropriate responses.
  - Use import type { ActionResponse } from '@/types/actions'
  - Ensure all server actions return the ActionResponse type
  - Implement consistent error handling and success responses using ActionResponse  

Key Conventions

1. Rely on Next.js App Router for state changes.
2. Prioritize Web Vitals (LCP, CLS, FID).
3. Minimize 'use client' usage:
  - Prefer server components and Next.js SSR features.
  - Use 'use client' only for Web API access in small components.
  - Avoid using 'use client' for data fetching or state management.
  Refer to Next.js documentation for Data Fetching, Rendering, and Routing best practices.
  - https://nextjs.org/docs

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set68

nextjs15-supabase-cursorrules-prompt-file A Cursor rule that keeps the agent inside a Next.js 15, Supabase and TypeScript strict stack — from session checks to RLS and Stripe keys. ★ 41,011repo stars nextjs-vercel-typescript-cursorrules-prompt-file A Cursor rule that sets code style and file structure for Next.js projects with TypeScript, Vercel middleware and a KV database. ★ 41,011repo stars nextjs-typescript-cursorrules-prompt-file A Cursor rule that pins the Next.js and TypeScript stack and the agent's working order: plan first, one file at a time, fixed reply format. ★ 41,011repo stars nextjs-tailwind-typescript-apps-cursorrules-prompt A Cursor rule that points the assistant at Next.js, Tailwind CSS and TypeScript. It sets the working order: plan in pseudocode first, code after. ★ 41,011repo stars nextjs-app-router-cursorrules-prompt-file A Cursor rule that hands the agent a set of Next.js App Router habits: server components by default, file-based routing, separate files for loading and errors. ★ 41,011repo stars netlify-official-cursorrules-prompt-file A Cursor rule that hands the agent Netlify's official conventions: function types, environment access, and no stray CORS headers. ★ 41,011repo stars nativescript-cursorrules-prompt-file A Cursor rule that tells the agent how to structure a NativeScript project and which libraries to reach for. ★ 41,011repo stars manifest-yaml-cursorrules-prompt-file A Cursor rule that tells the agent how to scaffold a small Manifest backend: project setup, the manifest/backend.yml file and limits on entities. ★ 41,011repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor