question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow handleSubmit to optionally return a promise and call setSubmitting automagically

See original GitHub issue

Simple 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:closed
  • Created 6 years ago
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
abumalickcommented, Sep 12, 2018

Did you have the change to explore the idea @jaredpalmer ?

The bad bot is trying to close the issue 🔨

4reactions
jaredpalmercommented, Jul 13, 2018

i think this is a good idea. will explore next week

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found