Allow handleSubmit to optionally return a promise and call setSubmitting automagically
See original GitHub issueSimple example from docs:
err => {
setSubmitting(false);
setErrors(err);
}
For now we have few separate setter functions (like setErrors
, setStatus
, etc.), each with simple notation f(params) => void
. API docs says that it is an imperative way to manage formik’s inner state. And I think of them as a set of setState callbacks where each one updates it’s own portion of formik state. This way of thinking conflicts with example above - when you have to call multiple setter callbacks in a row (finally, we’re not executing React’s setState this way).
More idiomatic api may look like this:
setSubmitting(false)
.then(() => setErrors(err));
Or React-way callback:
setSubmitting(false, () => setErrors(err))
But the simplest one still would be a plain f(params) => void
function for the whole state:
setFormikState({ isSubmitting: false, errors: err })
Also, this way we can skip extra re-render.
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (6 by maintainers)
Top Results From Across the Web
API Reference - Formik
The promise will be rejected if form is invalid. submitCount: number. Number of times user tried to submit the form. Increases when handleSubmit...
Read more >How do I change react state using a promise with Formik ...
So when you want to show the button, you call setStatus with some flag or value and in ... handleSubmit(values, { resetForm, setSubmitting, ......
Read more >formik - npm
Formik keeps track of your form's state and then exposes it plus a few reusable methods and event handlers ( handleChange , handleBlur...
Read more >util.promise - Prosody IM
Promises allow a non-blocking/asynchronous function to return a “promise” of a ... The function should call on_fulfilled(data) (where data is optional and ...
Read more >Building Forms in React with Formik [Examples] - KnowledgeHut
In order to create a form in JavaScript, we will use the most basic html input tag, which mostly comprises of input fields...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Did you have the change to explore the idea @jaredpalmer ?
The bad bot is trying to close the issue 🔨
i think this is a good idea. will explore next week