Values object not up to date with what's being typed on input #3441
Unanswered
zachkaigler
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there, I'm coming into a new codebase and working with Formik for the first time. Troubleshooting some error handling issues we're having and I'm noticing strange behavior with Formik's
values
object. My input field has anonChange
property that's receiving Formik'shandleChange
method as it's supposed to. It also has anonInput
property which is receiving a customhandleInput
function that was written by another dev, which updates a state variable in the parent component with the current values of each input as well as checks the form validity and toggles anerror
variable which also lives in the parent that toggles whether or not the user is allowed to continue to the next step in the form.The issue I'm having is that Formik's
values
object is always one step behind what the actual value entered into the input is. For example:User types "t" into email form
Formik's
values
object:{}
Formik's
errors
object:{}
Input event value: "t"
State variable value:
{email: "t"}
User types "te" into email form
Formik's
values
object:{email: "t"}
Formik's
errors
object:{email: "Invalid email"}
Input event value: "te"
State variable value:
{email: "te"}
Because I'm forced to use Formik's provided onChange handler I'm not sure what's causing this problem or how to fix it, but the fact that the internal values object is always one step behind the actual value means that my error handling isn't functioning properly. Can anyone help with what's going on here? Here's some code I've attempted to clean up and tighten a bit for clarity:
Beta Was this translation helpful? Give feedback.
All reactions