0
0
NextJSframework~5 mins

When to use client components in NextJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a client component in Next.js?
A client component is a React component that runs in the browser. It can use browser-only features like state, effects, and event handlers.
Click to reveal answer
beginner
When should you use a client component in Next.js?
Use client components when you need interactivity, like handling user input, animations, or dynamic updates that happen in the browser.
Click to reveal answer
intermediate
Why can't server components handle user events in Next.js?
Server components run on the server and do not have access to browser APIs or user events, so they can't handle clicks or input changes directly.
Click to reveal answer
beginner
How do you mark a component as a client component in Next.js?
Add the directive 'use client' at the top of the component file to tell Next.js to treat it as a client component.
Click to reveal answer
intermediate
Can client components use server components inside them in Next.js?
No, client components cannot include server components, but server components can include client components.
Click to reveal answer
Which of the following is a reason to use a client component in Next.js?
ATo fetch data from a database securely
BTo handle user clicks and input
CTo render static content faster
DTo run code only on the server
How do you tell Next.js that a component should be a client component?
AAdd 'use client' at the top of the file
BAdd 'use server' at the top of the file
CWrap the component in a special function
DName the file with .client.js extension
Which statement is true about client and server components?
AServer components can include client components
BBoth run only on the server
CClient and server components cannot be mixed
DClient components can include server components
What feature can only client components use in Next.js?
ADirect database queries
BServer-side data fetching
CStatic site generation
DReact hooks like useState and useEffect
If you want to add a button that changes text when clicked, which component type should you use?
AServer component
BStatic component
CClient component
DAPI route
Explain why and when you should use client components in Next.js.
Think about what needs to happen in the browser versus on the server.
You got /4 concepts.
    Describe the relationship between client and server components in Next.js and how they can be combined.
    Consider which components can contain which and where they run.
    You got /4 concepts.