Vercel’s Post

Vercel reposted this

View profile for Lee Robinson, graphic

VP of Product at Vercel

Demo of forms with React 19 and Next.js. If you've wondered... "Why does the form clear out my input values?" "How do I pass data from my server action → client?" "How do I handle client / server validation?" "How do I display inline errors next to inputs?" This should help!

Fre Vandeborne

Front-end web developer

1w

Lee Robinson, the thing that bothers me here is that useActionState does not provide a reset functionality. I've been using the same setup but when the form has been submitted successfully I remove it from the DOM and show a success message instead. That message has a `reset` button that should show the form again. My first instinct was to put a `key` on the component in the parent and pass in a function that generates a new key. But I ultimately solved this by adding a second form that calls the same action with a hidden input of value/name reset that returns the default object from the server. This response also returns `reset: true` and triggers a useEffect to reset my client side validation. It would be nice if we didn't have to call the server for something like that.

Aatef Baransy

Frontend Engineer II at Amazon Q Business

1w

Lee Robinson for persisting values across form submissions, what about storing the values in useState or some other state container? Do you think it’s better to pass the values back from the action as opposed to using controlled inputs? I think both are viable options. It seems to me like if you don’t really need to read the values elsewhere in the component (while the user is typing) then the approach you cover is preferable. Thanks for your and the team’s hard work on NextJS and Vercel :)

Tyson Lawrie

Passionate about AI enabled software engineering, cloud-native, DevOps, and automation.

1w

Isn’t this just Remix

Paul Gipson

AWS Solutions Architect Associate Certified | Terraform Certified | IT Specialist in Windows, Mac, Linux | Cloud & Infrastructure Management | Office 365 | Active Directory | End-User Support | Proactive Issue Resolution

1w

I’m a subscriber. Plans on integrating supabase/firebase or anything for backend?

This helps a lot! Thanks for this. A quick question: Usually I tend to use React Hook Form for this kind of forms. I assume, for this kind of form, there is no need for an extra library. What do you think?

Lucian Crisan💻👍

🚀 | Tech Leader | Typescript | React | Nodejs | Consultant Software Developer | 15+ years

1w

I have a good question. My client wants to use the form and play with the data without saving it to the backend but wants to get the live validation. and have a disable button Submit if the fields contain an error. how do you solve this problem with the new trend?

Steven Bennett

Seasoned software engineer with expertise in full-stack development, cloud infrastructure, and frontend technologies. Proven ability to drive project success through leadership, coding excellence, and automation.

2d

Is this on YouTube? I can’t get the video to go in landscape mode

Like
Reply

But how do I use the horse operator?

Konstantin Shuplenkov

CTO | Node.js developer | Cryptocurrency Enthusiast, 16+ years

1w

Thanks for the explanation

See more comments

To view or add a comment, sign in

Explore topics