Formik: Question: withFormik() resetting status

Created on 7 Mar 2018  路  4Comments  路  Source: formium/formik

I use the withFormik HOC and make use of the status variable to display a message for failed logins.

I use setStatus('Invalid credentilas') in handleSubmit and it is working fine. However I need to reset/empty the status when the user has changed/touched the username or password-field after the attempted submit.

From what I can gather, I can not use the handleChange to reset the status as handleChange is not availible in withFormik()?

using Formik 0.11

Most helpful comment

withFormik provides you handleChange and setStatus handlers. So somewhere in a tree you would do:

<input name="hello" onChange={e => {
  setStatus('')
  handleChange(e)
 }}
/>

All 4 comments

withFormik injects all these props https://github.com/jaredpalmer/formik#formik-props to your component.

Hm ok, not sure I understand. How/where exactly can I reset the status onChange when using withFormik?

withFormik provides you handleChange and setStatus handlers. So somewhere in a tree you would do:

<input name="hello" onChange={e => {
  setStatus('')
  handleChange(e)
 }}
/>

Ah, I understand now. Thanks!

Was this page helpful?
0 / 5 - 0 ratings