Why this matters
Ensures security and compatibility with RSC.
Use headers() and cookies() in Server Components, Route Handlers, or server actions; never in Client Components.
Ensures security and compatibility with RSC.
Side-by-side examples engineers can pattern-match during review.
'use client'
import { cookies } from 'next/headers'
const c = cookies()import { headers, cookies } from 'next/headers'
export default function Layout(){ const locale = headers().get('x-locale') ?? 'en'; return <html lang={locale}><body>{/* ... */}</body></html> }cookies() inside a Client Componentheaders() inside a server layoutFrom the same buckets as this rule.