InterviewBuddy
All interview questions

When should a component be marked use client?

Beginner

Answer

Add the use client directive at the top of a file when its component needs state, event handlers, effects, or browser APIs. Files imported under that boundary become part of the client module graph.

Explanation

Keep the boundary close to the interactive part to avoid sending unrelated server rendering code to the browser.

Example

"use client";
import {useState} from "react";