PluginBench
Rule

nextjs react typescript

via PatrickJS/awesome-cursorrules

Expert guidance for Next.js 14, React, TypeScript, and Web3 stack development

What is nextjs react typescript?

Comprehensive rule set for building type-safe, performant Next.js applications with React and TypeScript. Covers architectural patterns, error handling, component design, and integration with modern libraries like Shadcn UI, Tailwind, Viem, and Wagmi. Use this when building full-stack Next.js projects requiring strict typing and best-practice adherence.

  • Enforces functional, declarative React components with TypeScript interfaces and named exports
  • Implements server-side rendering (RSC) patterns while minimizing client-side overhead and 'use client' directives
  • Provides error handling strategies using guard clauses, early returns, and error boundaries for both expected and unexpected errors
  • Guides form validation and server actions using Zod, react-hook-form, useActionState, and next-safe-action
  • Establishes file structure, naming conventions, and code organization standards for scalability
  • Integrates Web3 libraries (Viem v2, Wagmi v2) and UI frameworks (Shadcn UI, Radix, Tailwind Aria) with type-safe patterns

Applies to

File patterns this rule matches.

**/*
Rule definition (reference)

Source of truth, from the repository.

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

Related rules

Next.js development guidance with SEO optimization and code quality standards.

**/*
41k
via PatrickJS/awesome-cursorrules

Next.js + Supabase + Shadcn + PWA development rules with code quality, build tracking, and project documentation standards.

**/*
41k
via PatrickJS/awesome-cursorrules

Next.js and Supabase setup for building a Todo app.

**/*
41k
via PatrickJS/awesome-cursorrules

Expert Next.js, Tailwind CSS, and TypeScript code generation with Supabase and RAG integration.

**/*
41k
via PatrickJS/awesome-cursorrules

Next.js App Router + TanStack Query v5 with HydrationBoundary, Server Actions, and optimistic updates

["app/**/*.tsx" +3
41k
via PatrickJS/awesome-cursorrules

Next.js App Router + TanStack Query v5 integration with HydrationBoundary, Server Actions, and optimistic updates.

**/*
41k
via PatrickJS/awesome-cursorrules