jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.98k stars 2.79k forks source link

accessing isValid inside validateForm function returns wrong data #3204

Open rosnk opened 3 years ago

rosnk commented 3 years ago

Bug report

Current Behavior

1) accessing "isValid" inside "validateForm" function returns wrong data 2) formic form renders multiple times when validateForm function is triggered manually. During this multiple render, if validation has failed.... in first render error object is empty and in second render error object is not empty (thus for one validateForm function execution, there is multiple error render with different values).

 Problem code link: https://snack.expo.io/@rosnk/formik-submit-test 

Expected behavior

1) want proper "isValid" value inside validateForm().then() function when promise has been resolved 2) It might be formik is internally setting the state thus there are multiple rerenders of the form, thus making isValid and error having different values in different renders. Is this different values in multiple render expected behavior in formik??

Reproducible example

https://snack.expo.io/@rosnk/formik-submit-test (can be scanned with expo app in phone and log can be checked)

Suggested solution(s)

n/a

Additional context

have my own implementation of mult-step forms and i want to validate on button click, if form is valid then proceed to next form step..... wrong value of "isValid" inside "validateForm" .then function is creating problem to implement my logic.

Your environment

Software Version(s)
Formik . "^2.2.6"
React . "16.13.1",
TypeScript . n/a
npm/Yarn . npm
Operating System mac
github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days