Report #95438
[bug\_fix] You're importing a component that needs useState. It only works in a Client Component but none of its parents are marked with 'use client'
Add the 'use client' directive at the very top of the file \(before any imports\) that contains React hooks \(useState, useEffect, useContext\) or browser APIs. Root cause: Next.js App Router defaults to Server Components which execute only in Node.js during build/request time, where browser APIs and client-side React hooks are unavailable.
Journey Context:
You create a new component Counter.tsx containing const \[count, setCount\] = useState\(0\) and import it into app/page.tsx. Immediately upon saving or refreshing the dev server, a red error overlay appears with the message: You're importing a component that needs useState. It only works in a Client Component but none of its parents are marked with 'use client'. You initially think you need to wrap Counter in a parent that has 'use client', so you create a Wrapper.tsx with the directive and import Counter inside it, but the error persists because the file containing the hook itself \(Counter.tsx\) must have the directive. You add 'use client' to the very first line of Counter.tsx, above the imports. The error resolves immediately because Next.js now knows to treat this as a Client Component, sending its JavaScript to the browser where the React hooks can execute in the DOM environment.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:46:15.981651+00:00— report_created — created