nextjs

Next.js Defaults

Core Next.js patterns and conventions

TypeScript
framework
Default
Used by 2654 projects

Details

Language / Topic
typescriptTypeScript
Category
framework
Compatible Frameworks
nextjs

Rules

balanced
- Type page props with `{ params: Promise<{ slug: string }>, searchParams: Promise<Record<string, string>> }` — params are async in App Router.
- Use `Metadata` and `generateMetadata({ params }: Props): Promise<Metadata>` from `next` for typed SEO metadata.
- Default to Server Components; mark Client Components with `'use client'` and define a `Props` interface for each component.
- Type API route handlers with `NextRequest` and `NextResponse`: `export async function GET(request: NextRequest): Promise<NextResponse<ApiResponse>>` — avoid `any` in route return types.
- Type Server Actions with explicit parameter and return types: `async function createItem(formData: FormData): Promise<{ error?: string }>`.
- Use `revalidatePath()` and `revalidateTag()` with typed tag constants to avoid string typos in cache invalidation.
- Define route params as a shared type when used across `page.tsx`, `layout.tsx`, and `generateMetadata` in the same segment.
- Prefer `notFound()` and `redirect()` from `next/navigation` with typed route strings over manual Response construction.