Next.js Discord

Discord Forum

server action on select

Answered
Yellowstripe scad posted this in #help-forum
Open in Discord
Yellowstripe scadOP
I am wondering how you can manage to work with server actions within a select, dropdown or whatever element that you would regularly use as a client and with a useState.

In guess we would have to wrap the select within a form and pass the action but how can the action be triggered without a onSubmit button?
Answered by Arinji
and inside the onChange you can just call your server action like a normal function @Yellowstripe scad
View full answer

8 Replies

@Yellowstripe scad the form stuff is a feature, but it's not the only feature
You can call server actions as normal functions as well
No need to wrap it in forms
Yellowstripe scadOP
Sorry I didn’t understand what you mean @Arinji
I am wondering how can you trigger something like an onChange without a useState using a server action
just make your normal client component with state and onChange events etc
and inside the onChange you can just call your server action like a normal function @Yellowstripe scad
Answer
Yellowstripe scadOP
OK. Will try it. Thanks !