Next.js Discord

Discord Forum

Can I call server actions like normal functions (with onclick or on submit)

Answered
Labib posted this in #help-forum
Open in Discord
I have this small confusion with server action. Every tutorial I saw always uses server actions with the form action or useFormState hook, sends the arguments as formdata and shows how it works even without javascipt enabled.

My question is is this the only recommended way? Can I just call it like a normal function and pass any arguments? Or does it create a security issue?
Answered by joulev
yes you can call it as ordinary functions.

as far as security is concerned, it is no different from using action={...}
View full answer

3 Replies