Next.js & App Router (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
When should you use the `'use client'` directive?
junior LevelDirectivesCLI
In Simple Words:
You only need to add 'use client' at the top of a file when the component requires:
- React hooks:
useState,useReducer,useEffect,useRef. - Interactive DOM event listeners:
onClick,onChange,onSubmit. - Browser APIs:
window,document,navigator,localStorage. - Custom hooks that depend on client state or context providers.
Rule of Thumb: Push 'use client' down to the leaves of your component tree. Keep parents as Server Components.