Importing useActionState from react fails in a Next.js project
import { useActionState } from 'react' fails after following the Next.js forms tutorialShort answer
useActionState exists only in React 19 and later. If the import fails, the project still resolves an older react package, or its TypeScript types are old. Run npm ls react @types/react, upgrade next, react, react-dom and the two type packages together, and check that a peer dependency conflict did not block the install.
Fix it fast
1Find out which cause you have
List the react and type packages that are really installed. Every react line should start with 19, and so should @types/react.
npm ls react react-dom @types/react @types/react-dom2Match what you see, then jump to its fix
- 1
npm ls shows react 18.xThe installed react package is older than 19Fix - 2
Editor or tsc reports the hook missing, while the app runs@types/react is still on version 18Fix - 3
Upgrading next alone did not change the react versionA Pages Router app takes its React version from package.jsonFix - 4
npm printed a peer dependency error, and package.json still shows the old reactThe upgrade install was rejected by another package's peer dependencyFix
- 1
What does the error look like?
import { useActionState } from 'react' fails after following the Next.js forms tutorialThe editor flags useActionState as not exported by reactThe tutorial used useFormState from react-dom, your code uses useActionState
Cause 1 of 4
The installed react package is older than 19
1Check
The React 19 release notes say React.useActionState replaced ReactDOM.useFormState from the canary builds. A project on react 18 has no such export.
npm ls react2Fix
Move next, react and react-dom to their latest versions together. Next.js 15 raised the minimum to React 19.
npm install next@latest react@latest react-dom@latest3Verify
The listing shows 19.x and the import resolves.
npm ls react react-domConfirmed by nextjs.org
Cause 2 of 4
@types/react is still on version 18
1Check
The runtime can be React 19 while the type packages are old. The Next.js upgrade guide says to upgrade @types/react and @types/react-dom for TypeScript projects.
npm ls @types/react @types/react-dom2Fix
Install the 19 type packages. The React upgrade guide gives this exact form.
npm install --save-exact @types/react@^19.0.0 @types/react-dom@^19.0.03Verify
Restart the TypeScript server in your editor and run the type check.
npx tsc --noEmitConfirmed by react.dev
Cause 3 of 4
A Pages Router app takes its React version from package.json
1Check
The installation guide says the App Router ships built-in React canary builds, while the Pages Router uses the version written in package.json. In a Pages Router app, nothing upgrades react unless you do.
grep -E '"(next|react|react-dom)"' package.json2Fix
Set react and react-dom to 19 yourself in package.json by installing them explicitly.
npm install react@latest react-dom@latest3Verify
Run the dev server and open the page that uses the hook.
npm run devConfirmed by nextjs.org
Cause 4 of 4
The upgrade install was rejected by another package's peer dependency
1Check
The upgrade guide lists this as a known snag. Some other package may still declare a peer range that excludes React 19.
npm ls react 2>&1 | grep -i -E 'invalid|ERESOLVE'2Fix
First update the package that rejects React 19. If you accept the risk, the upgrade guide names --force and --legacy-peer-deps as the ways to ignore the warning.
npm install react@latest react-dom@latest --legacy-peer-deps3Verify
Check that the listing now shows React 19 and run the project's own checks.
npm ls react
npm run buildConfirmed by nextjs.org
How do I stop it coming back?
- Upgrade next, react, react-dom and both @types packages in one command so they never drift apart.
- Commit the lockfile and install with npm ci in CI, so every machine gets the same React.
- When a tutorial pins a canary or rc build, read the Next.js version note on the page before copying its imports.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Upgrading to Next.js 16: middleware becomes proxy, and the other things that break
Missing Required default.js for Parallel Route
Next.js 16 renames middleware.ts to proxy.ts and its exported function to proxy.
6 causes, each with a fixWeb apps
Type error after upgrading: params does not satisfy the PageProps constraint
Type '{ params: { id: string; }; }' does not satisfy the constraint 'PageProps'
Since Next.js 15, params and searchParams are Promises, not plain objects.
4 causes, each with a fixWeb apps
TypeScript rejects a useRef ref passed to an input element
Type 'MutableRefObject<HTMLInputElement | undefined>' is not assignable to type 'LegacyRef<HTMLInputElement> | undefined'
The ref prop on a DOM element expects an object whose current value is the element or null.
2 causes, each with a fixWeb apps
TypeScript says a JSX element type has no construct or call signatures
'Promise<Element>' is not a valid JSX element
TypeScript accepts a capitalised JSX tag only when the value is a function component or a class component.
3 causes, each with a fixWeb apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fix