Performance: Use client directive
This affects how components are rendered and hydrated on the client, impacting initial load speed and interactivity.
export default function StaticComponent() { return <div>Hello, static content!</div>; }
"use client"; export default function StaticComponent() { return <div>Hello, static content!</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Server component (no "use client") | Minimal, static HTML | 0 | Low | [OK] Good |
| Client component with "use client" | Hydrated with JS event handlers | 1-2 | Medium | [!] OK |
| Unnecessary "use client" on static component | Hydrated unnecessarily | 1-3 | High | [X] Bad |
use client directive in Next.js?use clientuse client means browser-only code [OK]use client directive be placed in a Next.js component file?use client directive must be the first line in the file to be recognized properly.use client as the first line [OK]"use client";
import { useState } from 'react';
export default function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>Clicked {count} times</button>
);
}use client directiveuseState hook manages the count state, and the button updates it on click, so the count increments correctly.use client is present, hooks work normally [OK]use client is missingimport { useState } from 'react';
export default function Clicker() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>Clicked {count} times</button>
);
}use client directiveuseState hook but lacks the use client directive, which is required for client-side hooks.use client directive at the top -> Option Buse client directive [OK]use client directive to work [OK]useState and also fetches data from an API on the client side using useEffect. Which is the correct way to set up this component?useState, useEffect) and browser APIs, it must start with "use client";.useEffect to run after render, avoiding side effects during rendering.useEffect for fetching data."use client" and fetch inside useEffect [OK]use client directiveuseEffect"use server" directive incorrectlyPass the test and this pattern moves unknown