Recall & Review
beginner
What is a client-only module in Next.js?
A client-only module is a part of your Next.js app that runs only in the browser, not on the server. It is used for code that depends on browser APIs or user interactions.
Click to reveal answer
beginner
How do you mark a module as client-only in Next.js 14+?
You add the directive
'use client' at the top of the module file. This tells Next.js to load and run this module only on the client side.Click to reveal answer
intermediate
Why should you avoid using server-only modules inside client-only modules?
Server-only modules use Node.js or server APIs that don't exist in the browser. Using them in client-only modules causes errors because the browser can't run server code.
Click to reveal answer
intermediate
What happens if you forget to add 'use client' in a module that uses browser-only APIs?
Next.js will try to run the module on the server, causing errors like 'window is not defined' because browser APIs don't exist on the server.
Click to reveal answer
beginner
Give an example of when to use a client-only module in Next.js.
Use client-only modules for things like handling user input, animations, or accessing
localStorage, which only work in the browser.Click to reveal answer
What directive do you add to a Next.js module to make it client-only?
✗ Incorrect
The correct directive is 'use client' placed at the top of the module.
Which of these is a reason to use a client-only module?
✗ Incorrect
Browser APIs like localStorage only work in client-side code.
What error might you see if you use browser APIs in a server module?
✗ Incorrect
'window is not defined' happens because the server has no window object.
Where does a client-only module run in a Next.js app?
✗ Incorrect
Client-only modules run exclusively in the browser.
What happens if you forget 'use client' in a module that uses React hooks?
✗ Incorrect
React hooks require client components; without 'use client', Next.js treats the module as server-side.
Explain what a client-only module is in Next.js and why you would use it.
Think about where the code runs and what it needs to access.
You got /4 concepts.
Describe the consequences of not adding 'use client' to a module that uses browser features.
What happens when server tries to run browser code?
You got /4 concepts.