1

I am using Formik in my react application. I tried to change the state of button enbales/disabled using isSubmitting property but its not seems working. Neither button text updating nor styling. I have found a example solution but that's not working either. Here is the link of example code that isn't working. Can anyone explain please? Formik sandbox code example

1 Answer 1

4

You don't need to do anything special - formik automatically awaits the onSubmit handler. Just make sure it's returning a Promise that can be awaited.

In your example you are returning immediately from handleSubmit.

 async function handleSubmit(values, { setSubmitting }) { console.log("submitted"); setTimeout(() => setSubmitting(false), 2000); // this returns immediately } 

Update your example code like this:

 const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)) async function handleSubmit(values) { console.log("submitted", values); await delay(2000) } 

Edit formik-issubmitting-working (forked)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.