Saturday, May 18, 2024

Next.js - Server / Client Components

 To make a client component add 'use client' line to first line of your component file.

When to Use Client-side and Server-side Components in Next.js

Client-side Components

  • When to Use: Use client-side components when you need interactivity, state management, or access to browser-specific APIs.
  • Example Scenario: A component that handles user input, such as a form with validation, which requires user interactions and state updates.

Server-side Components

  • When to Use: Use server-side components when you need to render content that relies on data fetching from a server or when you need to keep certain logic secure on the server.
  • Example Scenario: A component that fetches and displays user data from a database, ensuring data is fetched securely on the server.

 


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Next.js Stack

Next.js 15 / React 19 PostgreSQL Prisma ORM TypeScript, ESLint & Zod ShadCN UI Next Auth React Hook Form Jest Testing Vercel Deployment