useFormState issues
Unanswered
Lakeland Terrier posted this in #help-forum
Lakeland TerrierOP
When deploying to vercel I am getting an error in the build logs
Attempted import error: 'experimental_useFormState' is not exported from 'react-dom' (imported as 'useFormState').
It does not throw error in my code editor.
The app builds and if I visit the deployment, it loads for a split second and then throws an
"Application error: a client-side exception has occurred (see the browser console for more information)"
The console reads
Error: Objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props}). If you meant to render a collection of children, use an array instead.
Here are the dependencies I am using
More code in comments
Any guesses as to what could be throwing the issue? I can upload more code and context if needed. Thank you for any potential help.
Attempted import error: 'experimental_useFormState' is not exported from 'react-dom' (imported as 'useFormState').
It does not throw error in my code editor.
The app builds and if I visit the deployment, it loads for a split second and then throws an
"Application error: a client-side exception has occurred (see the browser console for more information)"
The console reads
Error: Objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props}). If you meant to render a collection of children, use an array instead.
Here are the dependencies I am using
"dependencies": {
"@auth/prisma-adapter": "^1.0.6",
"@nextui-org/react": "2.2.9",
"@nextui-org/theme": "^2.2.3",
"@prisma/client": "^5.4.1",
"@types/ms": "^0.7.32",
"@types/node": "20.8.3",
"@types/react": "18.3.2",
"@types/react-dom": "18.2.11",
"autoprefixer": "^10.4.19",
"eslint": "8.51.0",
"eslint-config-next": "13.5.4",
"framer-motion": "11.2.5",
"ms": "^2.1.3",
"next": "v15.0.0-canary.1",
"next-auth": "beta",
"postcss": "^8.4.38",
"prisma": "^5.4.1",
"react": "19.0.0-rc-9d4fba0788-20240530",
"react-dom": "19.0.0-rc-9d4fba0788-20240530",
"tailwindcss": "^3.4.3",
"ts-node": "^10.9.1",
"typescript": "5.4.5",
"zod": "^3.23.8"More code in comments
Any guesses as to what could be throwing the issue? I can upload more code and context if needed. Thank you for any potential help.
6 Replies
Lakeland TerrierOP
'use server';
import { z } from 'zod'
const createCharacterSchema = z.object({
name: z.string().min(2).regex(/[a-zA-Z]+$/, { message: 'Must be a single name. No symbols, spaces or dashes.' })
})
interface CreateCharacterFormState{
errors: {
name?: string[];
}
}
export async function createCharacter(formState: CreateCharacterFormState, formData: FormData ): Promise<CreateCharacterFormState>{
const result = createCharacterSchema.safeParse({
name: formData.get('name'),
})
if (!result.success){
return {
errors: result.error.flatten().fieldErrors
}
}
return {
errors: {}
}
// TODO Revalidate the character select screen
}'use client'
import { experimental_useFormState as useFormState } from 'react-dom'
import {
Input,
Button,
Popover,
PopoverTrigger,
PopoverContent
} from '@nextui-org/react'
import * as actions from '@/actions'
export default function CharCreateForm() {
const [formState, action ] = useFormState(actions.createCharacter, {
errors: {}
})
return (
<Popover placement="left">
<PopoverTrigger>
<Button color="primary">Create new character</Button>
</PopoverTrigger>
<PopoverContent>
<form action={action}>
<div className="flex flex-col gap-4 w-80">
<h3 className="text-lg">
Create a new character
</h3>
<Input
name="name"
label="Name"
labelPlacement="outside"
placeholder="Name"
isInvalid={!!formState.errors.name}
errorMessage={formState.errors.name?.join(',')}
/>
<Button type="submit">Create</Button>
</div>
</form>
</PopoverContent>
</Popover>
)
}Lakeland TerrierOP
And this error in the build logs
▲ Next.js 15.0.0-canary.1
Creating an optimized production build ...
⚠ Found lockfile missing swc dependencies, run next locally to automatically patch
⚠ Found lockfile missing swc dependencies, run next locally to automatically patch
⚠ Found lockfile missing swc dependencies, run next locally to automatically patch
⚠ Compiled with warnings
./src/components/characters/CharCreateForm.tsx
Attempted import error: 'experimental_useFormState' is not exported from 'react-dom' (imported as 'useFormState').
Import trace for requested module:
./src/components/characters/CharCreateForm.tsx
✓ Compiled successfully
Linting and checking validity of types ...
Collecting page data ...
⚠ Found lockfile missing swc dependencies, run next locally to automatically patch
Generating static pages (0/5) ...
Generating static pages (1/5)
Generating static pages (2/5)
Generating static pages (3/5)
✓ Generating static pages (5/5)
Finalizing page optimization ...
Collecting build traces ...American Crow
Didn't read all the code but
https://react.dev/reference/react/useActionState
useFormState was renamed useActionState with React 19https://react.dev/reference/react/useActionState
Lakeland TerrierOP
I was having nextui issues with 19. I am going to try refactoring again
Giant panda
You should try to downgrade nextjs to previous release