nextjs - 💡(How to fix) Fix Form + useActionState example from React 19 docs causes error when using Next [7 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#84674Fetched 2026-04-08 02:18:47
View on GitHub
Comments
7
Participants
4
Timeline
16
Reactions
0
Author
Timeline (top)
commented ×7referenced ×5closed ×1issue_type_added ×1

Error Message

I expected the component to work in Next the same as it had in React's documentation. However, when visiting a Next route containing that example, the error below appears, indicating that useActionState can only be used within client components. That seems to contradict the React docs for that example, which explicitly require that the "<form> be rendered by a Server Component" for progressive enhancement to occur. Ecmascript file had an error This could instead be an issue with the React docs rather than with Next, but the CodeSandbox example in the docs (you can access it directly via the "fork" link) indeed appears to be a server component (it doesn't contain the "use client" directive), so I'm currently assuming this is particular to Next.

Code Example

Compiled /form in 398ms
./app/form/page.jsx:1:10
Ecmascript file had an error
> 1 | import { useActionState } from "react";
    |          ^^^^^^^^^^^^^^
  2 | import { signUpNewUser } from "./api";
  3 |
  4 | export default function Page() {

You're importing a component that needs `useActionState`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive.

 Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client

---

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.6.0-canary.53 // Latest available version is detected (15.6.0-canary.53).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/elegant-lederberg-2yjhcf

To Reproduce

  1. Visit the linked CodeSandbox.
  2. Start the dev server, if necessary.
  3. Open the preview, if necessary.
  4. Visit the /form route.

Current vs. Expected behavior

I expected the component to work in Next the same as it had in React's documentation. However, when visiting a Next route containing that example, the error below appears, indicating that useActionState can only be used within client components. That seems to contradict the React docs for that example, which explicitly require that the "<form> be rendered by a Server Component" for progressive enhancement to occur.

 ✓ Compiled /form in 398ms
 ⨯ ./app/form/page.jsx:1:10
Ecmascript file had an error
> 1 | import { useActionState } from "react";
    |          ^^^^^^^^^^^^^^
  2 | import { signUpNewUser } from "./api";
  3 |
  4 | export default function Page() {

You're importing a component that needs `useActionState`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive.

 Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.6.0-canary.53 // Latest available version is detected (15.6.0-canary.53).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

This could instead be an issue with the React docs rather than with Next, but the CodeSandbox example in the docs (you can access it directly via the "fork" link) indeed appears to be a server component (it doesn't contain the "use client" directive), so I'm currently assuming this is particular to Next.

extent analysis

TL;DR

Adding the "use client" directive to the file or its parent is likely the fix to resolve the error related to useActionState in a Next.js application.

Guidance

  • The error message indicates that useActionState can only be used within client components, suggesting a mismatch between the component's rendering context and its requirements.
  • To resolve this, add the "use client" directive at the top of the page.jsx file to ensure it's treated as a client component.
  • Verify that the component functions as expected after adding the directive by checking for the absence of the error message and the correct behavior of the form submission.
  • If issues persist, review the React documentation and Next.js guidelines for server and client components to ensure proper implementation.

Example

// page.jsx
'use client';
import { useActionState } from "react";
import { signUpNewUser } from "./api";

export default function Page() {
  // Component code here
}

Notes

The solution assumes that the component is intended to be a client component. If the component needs to be a server component for specific reasons (like SEO or static site generation), an alternative approach might be necessary, such as rearchitecting the component to not rely on useActionState or using a different state management solution compatible with server components.

Recommendation

Apply the workaround by adding the "use client" directive to the affected file, as this directly addresses the error message's suggestion and aligns with Next.js documentation for using client components.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix Form + useActionState example from React 19 docs causes error when using Next [7 comments, 4 participants]