I keep finding myself rewritting the same ol' submission logic for each form, with slight changes depending on the contents - however, each time, I write my logic into a separate script that looks really similar to the previous. Something along these lines:
- Disable the submission button
- Check and validate all the inputs
- Dispatch a post request
- Display the server errors if there was mistake,otherwise redirect/create a notification
Anyone able to help me out by sharing their solutions? Form submission patterns or frameworks to help me keep this a bit more dry are much appreciated 😄
Top comments (4)
Formik is solid. We used it where I used to work.
Build forms in React, without the tears 😭
Build forms in React, without the tears
Visit jaredpalmer.com/formik to get started with Formik.
The below readme is the documentation for the
canary(prerelease) version of Formik. To view the documentation for the latest stable Formik version visit jaredpalmer.com/formik/docsLet's face it, forms are really verbose in React. To make matters worse, most form helpers do wayyyy too much magic and often have a significant performance cost associated with them. Formik is a small library that helps you with the 3 most annoying parts:
By colocating all of the above in one place, Formik will keep things organized--making testing, refactoring, and reasoning about your forms a breeze.
Docs
In-browser Playgrounds
You can play with Formik in your web browser with these live online…
There is also Final Form, although I’ve never used it myself.
🏁 High performance subscription-based form state management for React
In the interest of making🏁 React Final Form the best library it can be, we'd love your thoughts and feedback.
Take a quick survey.
React Final Form is a thin React wrapper for Final Form, which is a subscriptions-based form state management library that uses the Observer pattern, so only the components that need updating are re-rendered as the form's state changes.
Getting Started
Philosophy
Examples
API
FAQ
In terms of posting the form and processing errors, it sounds like you’ve done the same thing a bunch of times. Maybe just create little helpers for that.
Formik seems exactly like what I'm looking for - thanks, I'll check it out 😊
Formik is leet 🔥
use Formik and stop re-writing logic, group it into re-usable pieces instead