Skip to main content
rule

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

A Cursor rule that pins down React, TypeScript, Next.js 14 and Node.js conventions: functional components, RORO, minimal use client.

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

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

The file is a rule set Cursor reads and applies while generating code. It asks for TypeScript everywhere, the function keyword for components instead of const, no classes and no enums, named exports, and the RORO pattern — receive an object, return an object. Directories use lowercase with dashes, as in components/auth-wizard.

Error handling gets its own section. Guards and edge cases go at the top of a function, early returns keep nesting flat, and the happy path sits last. Expected errors in Server Actions are modelled as return values through useActionState rather than try/catch, while unexpected ones land in error boundaries via error.tsx and global-error.tsx. For server actions the rule points to next-safe-action with Zod schemas and a shared ActionResponse type.

On the UI side it names Shadcn UI, Radix and Tailwind Aria, mobile-first responsive design, and WebP images with lazy loading. It also pushes you to cut use client, useEffect and setState in favour of server components. One thing to watch: the rule declares a stack that includes Solidity, Viem v2 and Wagmi v2 — for a plain web app those lines are dead weight, so trim them before you commit the file. It does not apply on its own: the metadata sets alwaysApply: false with globs at **/*.

What it helps with

  • lock a team into one React and TypeScript style
  • move data fetching off client components
  • structure Server Action errors without nested try/catch
  • wire type-safe actions with next-safe-action and Zod
  • settle file naming and component layout

Example prompts for the agent

  • Build a login form component following the project rules: server component, Zod validation, named export
  • Rewrite this Server Action with next-safe-action returning ActionResponse and early returns
  • Scan this component for unnecessary use client and useEffect and suggest what moves to an RSC

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

Manually: put the files in place

.cursor/rules/react-typescript-nextjs-nodejs-cursorrules-prompt-.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 react-typescript-nextjs-nodejs-cursorrules-prompt-

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

Place the file at .cursor/rules/react-typescript-nextjs-nodejs-cursorrules-prompt-.mdc in your project root. Cursor picks it up as a rule.

What does this rule do?

It sets coding conventions for React, TypeScript, Next.js 14 App Router and Node.js: functional style, RORO, early returns on errors, few client components, and Shadcn UI plus Tailwind Aria for styling.

Does it apply to every file automatically?

No. The metadata has alwaysApply: false, and globs is set to **/*, so the scope is broad but auto-apply is off.

Source text

react-typescript-nextjs-nodejs-cursorrules-prompt-.mdc · CC0-1.0
---
description: "Cursor rules for React development with TypeScript, Next.js, and Node.js 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()).
- 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.

Dependencies:

- Next.js 14 App Router
- Wagmi v2
- Viem v2

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
  - Example:
    ```typescript
    'use server'
    import { createSafeActionClient } from 'next-safe-action'
    import { z } from 'zod'
    import type { ActionResponse } from '@/app/actions/actions'
    const schema = z.object({
      value: z.string()
    })
    export const someAction = createSafeActionClient()
      .schema(schema)
      .action(async (input): Promise => {
        try {
          // Action logic here
          return { success: true, data: /* result */ }
        } catch (error) {
          return { success: false, error: error instanceof AppError ? error : appErrors.UNEXPECTED_ERROR, }
        }
      })
    ```

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.

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

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set68

shopify-theme-dev-liquid A Cursor rule collecting Shopify theme practices across Liquid, JavaScript, CSS, accessibility and performance. Useful when you build a theme and want the agent to keep the structure. ★ 41,011repo stars salesforce-apex-cursorrules-prompt-file A Cursor rule that points the agent at Salesforce Apex work: queueables instead of @future, GoF patterns, and almost no comments. ★ 41,011repo stars rtl-right-to-left-i18n-cursorrules-prompt-file A Cursor rule that pushes the agent toward logical CSS and Tailwind utilities instead of left/right. Useful when the app has to run in Arabic, Hebrew, Persian or Urdu. ★ 41,011repo stars react This rule hands Cursor a set of React conventions: component structure, hooks, state, forms and accessibility. Useful when a project has plenty of .tsx and .jsx and you want one style. ★ 41,011repo stars react-styled-components-cursorrules-prompt-file A Cursor rule that tells the agent how to write React code with styled-components: functional components, theming through ThemeProvider, a fixed folder layout. ★ 41,011repo stars react-query-cursorrules-prompt-file A Cursor rule that tells the agent how to write React Query code: where QueryClient lives, how hooks and query keys are named. ★ 41,011repo stars react-native-expo-cursorrules-prompt-file A Cursor rule that tells the agent how to write React Native code with Expo. Useful when you want new screens and components to follow one stack. ★ 41,011repo stars rails-cursorrules-prompt-file A Cursor rule file that tells the agent how to write Rails 8 code: generators, bin/dev, the Solid stack, Minitest and Hotwire. ★ 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