Next.js Discord

Discord Forum

Is there a way to use a server action in this scenario?

Answered
Noronha posted this in #help-forum
Open in Discord
Let's say I have a ClientPage that is server-side and that renders a <ClientForm /> component that is a client component.

Alright now we inside this form, we should have a <CitySelector /> component that when the user selects a "State", we'll fetch all cities from that state and render in a select/combobox. Is there a way that we can make CitySelector use server actions to fetch this data or I'll have to 100% of the time fallback to fetch?
Answered by Ray
yeah I think you could do something like this
 <select
  onChange={async (e) => {
    const result = await action(e.target.value);
    setResult(result);
  }}
></select>
View full answer

3 Replies