When you need the browser
State, events, refs, browser APIs, third-party UI libraries (Framer Motion, headless UI, React Hook Form). For these, declare the file a Client Component with 'use client' at the very top.
The directive is contagious
'use client' applies to the file and everything it imports. Anything in the import graph below the directive is part of the client bundle. Place it as low in the tree as possible.
The decision table
| Need | Where |
|---|---|
useState / useEffect / useRef | Client |
Event handlers (onClick, onChange, onSubmit) | Client |
window, document, localStorage | Client |
| Third-party hook-based libraries | Client |
| Plain rendering of data | Server |
| Data fetching / DB queries | Server |
| Reading secrets | Server |
| Heavy data shaping | Server |