Next.js 'use client': When You Actually Need It
In Next.js you need 'use client' in only three cases: the component uses hooks such as useState or useEffect, it handles events such as onClick or onChange, or it touches browser features such as window and localStorage. Everything else is better left on the server. Put the directive on the small interactive component, not on the whole page.
What does 'use client' actually do?
In the App Router, components run on the server by default: they arrive as HTML and ship none of their own code to the browser. Adding 'use client' at the top of a file draws a boundary between server and client. That file and everything it imports is sent to the browser as JavaScript.
One detail is often missed: a client component is still rendered to HTML on the server for the first load. The difference is that its code is also shipped to the browser and hydrated there.
Recommendation: think of the directive as a boundary, not as a switch that silences errors. Every import below that boundary lands in the client bundle.
When is 'use client' required?
There are three clear cases:
- Hooks: useState, useEffect, useRef, useContext and any custom hooks built on them.
- Events: handlers such as onClick, onChange and onSubmit that respond to user actions.
- Browser features: window, document, localStorage and other APIs that exist only in the browser.
Recommendation: if a component has none of the three, leave the directive out. Fetching data, rendering text and lists, and laying out the page all work on the server.
Why is adding it everywhere a problem?
Adding 'use client' to every component makes the error go away, but it makes the page heavier. The browser has to download, parse and run more JavaScript, which is most noticeable on low-end phones and slow connections.
You also give up what server components offer. On the server you can query a database or an internal API directly, and secret keys never reach the browser. A client component cannot do that.
Recommendation: when an error appears, do not add the directive straight away. Find out which component triggers it and isolate only that part.
Where should the boundary go?
Push the boundary as far down the component tree as you can. If the only interactive element on a product page is the "Add to cart" button, move that button into its own file and put the directive there. The title, description and images stay on the server.
You also do not need the directive in every file. Anything a client component imports becomes part of the client side automatically.
Recommendation: keep page and layout files as server components, and split interactive parts into small, separate components.
Can a server component live inside a client component?
Yes, but not through an import. A component imported into a client file becomes a client component. Pass the server component as children or another prop instead: a collapsible panel can be a client component while the content inside it is rendered on the server.
Props passed from server to client must be serializable: strings, numbers, arrays, plain objects. An ordinary function cannot be passed this way.
Recommendation: use the children pattern for wrappers such as context providers and modals. The official Next.js documentation covers the details.
How do you find unnecessary 'use client' directives?
Search the project for the use client string and ask three questions about each file: is there a hook, is there an event handler, is there a browser API? If all three answers are no, remove the directive and rebuild the project.
Recommendation: start the audit with page and layout files. A single unnecessary directive there moves the whole tree to the client.
Quick summary
- In the Next.js App Router, components run on the server by default.
'use client'is only needed for hooks, event handlers and browser APIs.- The marked file and all of its imports are shipped to the browser as JavaScript.
- Place the boundary on a small interactive component, not on the whole page.
- Pass server content into client components through children.
Frequently asked questions
Does a 'use client' component never run on the server?
It does: on the first load it is rendered to HTML on the server. Its code is then loaded in the browser and becomes interactive.
Do I need 'use client' in every client file?
No. The directive goes only in the boundary file, and the files it imports move to the client side on their own.
Can I use a server component inside a client component?
Yes, if you pass it as children or another prop. If you import it directly, it becomes a client component too.