Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/elegant-lederberg-2yjhcf
To Reproduce
- Visit the linked CodeSandbox.
- Start the dev server, if necessary.
- Open the preview, if necessary.
- 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.
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/elegant-lederberg-2yjhcf
To Reproduce
/formroute.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
useActionStatecan 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.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/AWhich 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.