Directives

use client directive

Place the directive before imports in a client entry module. Its dependencies may enter the browser bundle. The server may still produce initial HTML for that component. Use effects or events for browser-only operations. Source: https://react.dev/reference/rsc/use-client. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.

Formal Syntax & Structure

nextjs syntaxnextjs
"use client";

Working Example

Example Snippetnextjs
'use client';import {useState} from 'react';export default function Counter(){const [n,setN]=useState(0);return <button onClick={()=>setN(n+1)}>Count: {n}</button>;}
Next.js Reference