Next.js Discord

Discord Forum

fetching data in a form handler clientside. am I an idiot?

Answered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
I am using react hook form and zod to manage my form and validate my data.

In my formHandler function I need to use data from the form inputs to fetch data from an API.

I am using useState to manage a few different states of the page for success and failure conditions and isSubmitting type things, so my page needs to be a client component.

For the async/await fetch
I have explored useEffect() watching the true/false of isSubmitting but I cannot get it to work and I am now wondering if I am thinking about this all wrong. Next keeps yelling at me about I cant use async/await in client components.

Everything i read says fetch data on the server, but i dont see how I can in this instance.

can someone help me with my understanding of this concept here.

thanks!
Answered by Arinji
Well, you can call server actions from the form
View full answer

5 Replies

Well, you can call server actions from the form
Answer
those are run on the server
await them, and then update your state
West African LionOP
💯
@West African Lion 💯
Mark an answer if it solved your question :D