Skip to content

Next.js React TypeScript .cursorrules prompt file

Author: wslyvh

What you can build

Decentralized Finance (DeFi) Dashboard: Create a web application that uses Solidity for smart contract interactions and displays real-time analytics of a user's DeFi portfolio using Next.js for SSR and Radix UI for component design.Tokenized Asset Marketplace: Develop a platform where assets are tokenized using Solidity, and users can trade them. Use Next.js with server-side rendering for a fast user experience and Wagmi for Ethereum integration.NFT Collection Viewer: Build an app that allows users to view their NFT collections by connecting their wallets. Utilize TypeScript for type safety and Shadcn UI for a responsive design.Automated Solidity Code Review Tool: Create a service that analyzes Solidity code for potential vulnerabilities and optimizations, providing feedback with concise examples. Use Node.js for the backend processing.Collaborative Coding Environment with Compiler Features: Develop a real-time collaborative coding platform that supports Solidity, TypeScript, and other languages. Use Vite for fast builds and Tailwind CSS for a seamless design.Web3 Community Platform: Create an interactive platform for web3 enthusiasts to share knowledge and projects. Integrate Solidity-based smart contracts for user reputation and use Next.js for a dynamic content experience.Dynamic Form Builder with Zod Validation: Build an application for creating customizable web forms that leverage Zod for type validation. Use React and Tailwind Aria for styling, ensuring accessibility and responsiveness.Cryptocurrency Wallet Application: Develop a secure wallet application using TypeScript and React for interacting with various blockchain networks. Implement Viem for efficient Ethereum operations and Tailwind CSS for UI design.Blockchain-Based Voting System: Create a decentralized voting platform using Solidity for managing elections securely. Use Next.js for the frontend interface and ensure dynamic component loading for a smooth experience.Interactive Tutorials for Learning Solidity: Build an educational platform offering guided Solidity coding tutorials, featuring live code execution. Use Node.js for the backend and implement interactive UI components with Radix.

Benefits

Synopsis

Developers building Next.js applications with TypeScript and React who want to implement efficient error handling, responsive design, and optimized server/client interactions will benefit from this prompt.

Overview of .cursorrules prompt

The .cursorrules file outlines comprehensive guidelines for developers working with technologies including Solidity, TypeScript, Node.js, Next.js, React, and several UI and styling frameworks. It emphasizes writing concise and accurate TypeScript code using functional, declarative programming paradigms. Key principles include module reuse, descriptive naming conventions, and a preference for named exports. The file provides specific structure and syntax recommendations for JavaScript/TypeScript, enforces robust error handling, and advocates for using certain tools and libraries for UI development. For React/Next.js applications, it prescribes functional components, mobile-first responsive design, and best practices for state management and error handling. Furthermore, it highlights conventions for server actions, using Zod for validation, and strategies for optimizing performance and handling errors. The file also stresses adhering to Next.js documentation for best practices in data fetching and rendering.

.cursorrules Content

json
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 Conventions1. 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

Released under the MIT License.