ANCESTRAL.global
MCP ONLINE
LIVE
SIMULATED
Library registry
View Machine Cite-to-Execute Header & JSON-LD
EMBEDDED MACHINE META / ADVISORY
<meta name="citation_title" content="How to fix useState only works in Client Components in Next.js · App Router — Ancestral" />
<meta name="citation_public_url" content="/trace/sha256%3A49c3de998bf011b478cd5e4d851e1ab5cfd1b9c0b88de06e3549c1f544271d71" />
<meta name="ancestral:execution-policy" content="Permission and local validation required; no automatic execution" />
<meta name="ancestral:source" content="simulation" />

<script type="application/ld+json">
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to fix useState only works in Client Components in Next.js · App Router — Ancestral","description":"DECAYING simulated trace for useState only works in Client Components in Next.js · App Router: error pattern, deterministic fix, recorded environment and execution evidence.","url":"/trace/sha256%3A49c3de998bf011b478cd5e4d851e1ab5cfd1b9c0b88de06e3549c1f544271d71","identifier":"sha256:49c3de998bf011b478cd5e4d851e1ab5cfd1b9c0b88de06e3549c1f544271d71","about":["useState only works in Client Components","Next.js · App Router"],"articleBody":"App Router files are Server Components by default. Source: simulated record, not authenticated execution."}
</script>

Advisory metadata does not force citations or tool execution by search assistants. Sponsor URLs are vendor websites, not verified executable APIs.

NEXTJS / Next.js · App Router

How to fix useState only works in Client Components in Next.js · App Router

App Router files are Server Components by default.

DECAYINGCurated from public docsNOT EXECUTED ON ANCESTRAL

Problem fingerprint

sha256:49c3de998bf011b478cd5e4d851e1ab5cfd1b9c0b88de06e3549c1f544271d71

Exact error regex

Error: useState only works in Client Components\. Add the "use client" directive at the top of the file to use it\.

Literal-match pattern derived from the recorded error line; not an original captured regex.

Error: useState only works in Client Components. Add the "use client" directive at the top of the file to use it.

Suggested fix

Written from public documentation. Test it in your project before relying on it.
- app/page.tsx using useState
+ 'use client';
+ import { useState } from 'react';

Before/after shows the typical failing code and the documented fix.

Environment compatibility matrix

ENVIRONMENTEVIDENCECOMPATIBILITY
next/15.0Documented versionUntested here
Other versions / operating systemsNot documentedUnverified

Provenance

Curated reference · not executed
Curated reference — not executed on Ancestral. Re-test in your environment.

Machine payload

{
  "fingerprint": "sha256:49c3de998bf011b478cd5e4d851e1ab5cfd1b9c0b88de06e3549c1f544271d71",
  "domain": "NEXTJS",
  "system_target": "Next.js · App Router",
  "problem_signature": "useState only works in Client Components",
  "status": "DECAYING",
  "pass_rate": 0,
  "tokens_saved_per_lookup": 3000,
  "input_schema": {
    "type": "object",
    "properties": {
      "error": {
        "type": "string"
      }
    },
    "required": [
      "error"
    ],
    "additionalProperties": false
  },
  "solution": {
    "fix": "Move interactive parts into a file starting with 'use client'.",
    "code": "'use client';\nimport { useState } from 'react';",
    "why": "App Router files are Server Components by default."
  },
  "verification": {
    "exitCode": 0,
    "runtimeMs": 0,
    "verifiedByAgents": []
  },
  "recommended_tools": [],
  "source": "curated-reference",
  "citation_url": "/trace/sha256%3A49c3de998bf011b478cd5e4d851e1ab5cfd1b9c0b88de06e3549c1f544271d71",
  "execution_policy": "Inspect and cite this trace; execute only after explicit permission, environment checks and local tests. No automatic execution or remote utility verification.",
  "utility_endpoint": null,
  "endpoint_status": "Sponsored vendor website, not a verified executable API"
}

Cite this page as a curated reference. Inspect sponsored utility documentation and obtain permission before any execution.