formData.get is not a function - Server actions
Unanswered
North Pacific hake posted this in #help-forum
North Pacific hakeOP
Hello folks, I'm getting this error formData.get is not a function when I'm trying to get the form values:
here is my code:
here is my code:
import { createCategoria } from "@/actions/create"
import { ButtonSubmit } from "@/components"
export default function AdminPainel(){
const submit = async (formData: FormData) => {
'use server'
const { name } = Object.fromEntries(formData);
const data = typeof name === 'string' ? name : '';
await createCategoria(data)
}
return (
<>
<div className="w-full p-5 flex flex-col">
<h1>Adicionar categoria</h1>
<form action={submit} className="flex mt-5 flex-col gap-2 w-3/12 items-center">
<input
type="text"
name="name"
placeholder="Nome da categoria"
className="p-2 rounded-lg w-full bg-white dark:bg-zinc-800 px-5 focus:outline-none"
/>
<ButtonSubmit text="Adicionar" />
</form>
</div>
</>
)
}16 Replies
North Pacific hakeOP
I didn't change a thing, I just restarted my PC and now everything works fine
Oh well, another mysterious next issue fixed by restarting
North Pacific hakeOP
Opps! there's something wrong with server actions.
As I said earlier it worked after restarting my PC... BUT after few tests its broken again...
As I said earlier it worked after restarting my PC... BUT after few tests its broken again...
could you make a minimal reproduction repository? so i can clone and debug
because your code here looks good
@joulev https://l.joulev.dev/mrr
refer to here on how to make a reproduction repository
North Pacific hakeOP
@North Pacific hake this is repository link:
https://github.com/abel-banze/workdeal.git
please, help me
this repo is too big, how do i find all the environment variables needed for the project to run? please reduce it to a very minimal state where the problem is still present, without requiring third party integrations like databases, auth and so on
the link above gives you a list of steps to follow to do that
https://github.com/abel-banze/workdeal/blob/main/actions/create/index.ts
I think you're missing
I think you're missing
'use server'; in this filehttps://github.com/abel-banze/workdeal/blob/main/app/(protected)/(dashboard)/concursos/create/page.tsx
And remove
And remove
'use server' at line 13.let me know if it works