Skip to content

Step 14 - Client and server components

Course: NextJS (Client side) - chapter 14

Ref - https://nextjs.org/learn/react-foundations/server-and-client-components

NextJS expects you to identify all your components as either client or server

As the name suggests

  1. Server components are rendered on the server
  2. Client components are pre-rendered and are pushed to the client to be rendered again By default, all components are server components.

If you wan’t to mark a component as a client component, you need to add the following to the top of the component -

"use client"

When should you create client components ?

  1. Whenever you get an error that tells you that you need to create a client component
  2. Whenever you’re using something that the server doesn’t understand (useEffect, useState, onClick…) Rule of thumb is to defer the client as much as possible

Try updating components/Signin.tsx to make it a client component

You will notice that the error goes away

Some nice readings -

https://github.com/vercel/next.js/discussions/43153