DEV Community

Cover image for Server Components Vs Client Components
Ashish Prajapati
Ashish Prajapati

Posted on

2 1 2

Server Components Vs Client Components

For quite a while, I have been exploring more about the Server and Client components in NextJS and why they differ from each other and what are pros and cons of them.

Here are the some of the key differences between Server and Client components, which will help you to understand more about it.

Server-VS-Client-Components

Server Components

  • By default all of the components are Server Components in NextJS.
  • It may help reduce the amount of js bundle size sent to client.
  • They run only on server, no hydration is required at all.
  • It can access the server resources, which may help to do server only stuff which is not possible in client side.
  • Allows to fetch data on server which may help to reduce the network latency and results in better loading timefor page.
  • We can pass Client components as child of Server components.
  • We can only use "use" hook in server components.
  • They do not support any user interactions like clicking event.

Client Components

  • To create a Client Component, add "use client" to very top of the file before any import statements.
  • It increases the js bundle size needed in client side.
  • It run on both server and client, it requires hydration.
  • It runs on client side, so it has limited amount of resources.
  • All data fetching happens in client, so increased latency for loading the page.
  • We can pass Server Components as child of Client components
  • We can use all of the hooks in client components.
  • They support all of the user interactions like clicking event.

Heroku

Amplify your impact where it matters most β€” building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (4)

Collapse
 
aniruddhaadak profile image
ANIRUDDHA ADAK β€’

So well written! You made it easy to understand! ✍️

Collapse
 
ashishsimplecoder profile image
Ashish Prajapati β€’

Thank you

Collapse
 
mohitshrivas profile image
Mohit shrivas β€’

point good explaination

Collapse
 
ashishsimplecoder profile image
Ashish Prajapati β€’

Thank you

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment JosΓ© and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video πŸŽ₯