Next.js Discord

Discord Forum

Confused about docs: "Passing Additional Arguments to Server Action"

Unanswered
Ramon posted this in #help-forum
Open in Discord
Hello, I was reading the docs about the new feature "Server Actions" (https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#passing-additional-arguments) it explicitely reads "You can pass additional arguments to a Server Action using the JavaScript bind method.".

Instead of binding const updateUserWithId = updateUser.bind(null, userId) and then passing it to the <form action={updateUserWithId} wouldn't it be simpler to do <form action={(formData) => updateUser(userId, formData)? Are they equivalent?

Thanks for your help.

2 Replies

Singapura
@Ramon Did you find an answer?
I think the .bind approach also works when js is disabled while the other approach doesn’t. Never tested though.