useActionState not available and useFormState won't let me build, issue with server actions
Answered
mjk134 posted this in #help-forum
mjk134OP
Hi guys, i recently created a nextjs project, setup a form with a server action but useActionState was not available? Instead I tried useFormState, which works in dev, but causes an error in build. The error for the build was because there is no type definition for it?
Answered by American Crow
├── react@18.3.1
├── react-dom@18.3.1
├── next@14.2.3
├── typescript@5.4.5
with
├── react-dom@18.3.1
├── next@14.2.3
├── typescript@5.4.5
with
useFormState is working for me. (Make sure vscode is using the typescript version from workspace/package.json)7 Replies
American Crow
Which next version are you on?
Below that as you said useFormState is the way to go. Whats the build error?, what version of typescript you on
useActionState is only available on React’s Canary / Next Canary afaik.Below that as you said useFormState is the way to go. Whats the build error?, what version of typescript you on
American Crow
├── react@18.3.1
├── react-dom@18.3.1
├── next@14.2.3
├── typescript@5.4.5
with
├── react-dom@18.3.1
├── next@14.2.3
├── typescript@5.4.5
with
useFormState is working for me. (Make sure vscode is using the typescript version from workspace/package.json)Answer
@American Crow ├── react@18.3.1
├── react-dom@18.3.1
├── next@14.2.3
├── typescript@5.4.5
with `useFormState` is working for me. (Make sure vscode is using the typescript version from workspace/package.json)
mjk134OP
according to my package.json:
- typescript@^5
- react@^18
- react-dom@^18
- next@14.2.3
The error:
- typescript@^5
- react@^18
- react-dom@^18
- next@14.2.3
The error:
./src/components/creator-setup-form.tsx:3:10
Type error: Module '"react-dom"' has no exported member 'useFormState'.
1 | "use client";
2 | import { Button } from "./ui/button";
> 3 | import { useFormState, useFormStatus } from "react-dom";
| ^
4 | import { useState } from "react";
5 | import { Tabs, TabsList, TabsTrigger } from "./ui/tabs";
6 |ah it might be because its resolving just react 18
ill try update it
American Crow
check the actually installed versions by running
or make the minimum versions the ones i posted
bun pm ls (or the equivalent of the package manager you are using)or make the minimum versions the ones i posted
@American Crow check the actually installed versions by running `bun pm ls` (or the equivalent of the package manager you are using)
or make the minimum versions the ones i posted
mjk134OP
yup, looks like it was using just 18 instead of the versions you listed above, looks like the types have been fixed