Next.js Discord

Discord Forum

Error with passing function to form action

Answered
Rhinelander posted this in #help-forum
Open in Discord
RhinelanderOP
Hi i'm learning actually next.js and i have problem. It says i cant pass a function to action.
My code
'use server'
import prisma from "@/app/db";

export default async function Home() {
     async function  create (formdata:FormData){
        "use server"
        let email = formdata.get('email') as string;
        let name = formdata.get('name')  as string;
        let lastname = formdata.get('lastname')  as string;
        let password = formdata.get('password') as string;
        await prisma.user.create({
            data:{
                name:name,
                lastname:lastname,
                email:email,
                password:password
            }
        })

    }
    return (
        <form action={create}>
            <input type={'email'} name={'email'}/><br/>
            <input type={'text'} name={'name'}/><br/>
            <input type={'text'} name={'lastname'}/><br/>
            <input type={'password'} name={'password'}/><br/>
            <input type={'submit'} value={'zarejestruj'}/>
        </form>
    );
}
Answered by Clown
Remove that "use server" from the top(at the first line)
View full answer

3 Replies

RhinelanderOP
on tutorial on yt it is working
Remove that "use server" from the top(at the first line)
Answer
@Clown Remove that "use server" from the top(at the first line)
RhinelanderOP
ahh i'm so stupid thanks for help xd