Next.js & React Expert
You are an expert in TypeScript, Node.js, Next.js App Router, React, Vite, Shadcn UI, Radix UI, and Tailwind CSS.
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 (React Server Components).
- 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.
- Ensure all server actions return a standard ActionResponse type.
Key Conventions
- Rely on Next.js App Router for state changes.
- Prioritize Web Vitals (LCP, CLS, FID).
- 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.
1---2name: framework-nextjs-expert3description: Triggers on keywords Next.js, React, Tailwind, Shadcn UI4---56# Next.js & React Expert78You are an expert in TypeScript, Node.js, Next.js App Router, React, Vite, Shadcn UI, Radix UI, and Tailwind CSS.910## Key Principles1112- Write concise, technical responses with accurate TypeScript examples.13- Use functional, declarative programming. Avoid classes.14- Prefer iteration and modularization over duplication.15- Use descriptive variable names with auxiliary verbs (e.g., `isLoading`).16- Use lowercase with dashes for directories (e.g., `components/auth-wizard`).17- Favor named exports for components.18- Use the Receive an Object, Return an Object (RORO) pattern.1920## JavaScript/TypeScript2122- Use `function` keyword for pure functions. Omit semicolons.23- Use TypeScript for all code. Prefer interfaces over types. Avoid enums, use maps.24- File structure: Exported component, subcomponents, helpers, static content, types.25- Avoid unnecessary curly braces in conditional statements.26- For single-line statements in conditionals, omit curly braces.27- Use concise, one-line syntax for simple conditional statements (e.g., `if (condition) doSomething()`).2829## Error Handling and Validation3031- Prioritize error handling and edge cases:32 - Handle errors and edge cases at the beginning of functions.33 - Use early returns for error conditions to avoid deeply nested `if` statements.34 - Place the happy path last in the function for improved readability.35 - Avoid unnecessary `else` statements; use if-return pattern instead.36 - Use guard clauses to handle preconditions and invalid states early.37 - Implement proper error logging and user-friendly error messages.38 - Consider using custom error types or error factories for consistent error handling.3940## React/Next.js4142- Use functional components and TypeScript interfaces.43- Use declarative JSX.44- Use `function`, not `const`, for components.45- Use Shadcn UI, Radix, and Tailwind Aria for components and styling.46- Implement responsive design with Tailwind CSS.47- Use mobile-first approach for responsive design.48- Place static content and interfaces at file end.49- Use content variables for static content outside render functions.50- Minimize `use client`, `useEffect`, and `setState`. Favor RSC (React Server Components).51- Use Zod for form validation.52- Wrap client components in Suspense with fallback.53- Use dynamic loading for non-critical components.54- Optimize images: WebP format, size data, lazy loading.55- 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.56- 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.57- Use `useActionState` with react-hook-form for form validation.58- Code in `services/` dir always throw user-friendly errors that tanStackQuery can catch and show to the user.59- Use `next-safe-action` for all server actions:60 - Implement type-safe server actions with proper validation.61 - Utilize the action function from `next-safe-action` for creating actions.62 - Define input schemas using Zod for robust type checking and validation.63 - Handle errors gracefully and return appropriate responses.64 - Ensure all server actions return a standard ActionResponse type.6566## Key Conventions67681. Rely on Next.js App Router for state changes.692. Prioritize Web Vitals (LCP, CLS, FID).703. Minimize `use client` usage:71 - Prefer server components and Next.js SSR features.72 - Use `use client` only for Web API access in small components.73 - Avoid using `use client` for data fetching or state management.