Reputation: 219
https://codesandbox.io/s/friendly-bohr-mjyhc
This is the code snippet of my form, I have created a field and I want to change its value onChange. I don't see the value changing on the screen and when I console log the event.target.value I only see the current letter being replaced from the previous letter (if I type AB, the console log values show A and then it replaces to B)
Upvotes: 0
Views: 3135
Reputation: 26732
Formik
library itself provides various method to handle the complexity.
In your code rather than adding a custom handle Change you can directly use handleChange
method.
Simply replace -
onChange={customChange}
with
onChange={handleChange}
to make this work.
FYI - I also printed values
so that you can see the formik
bag of values.
Here is the working code - Code Sandbox
EDIT 1 -
If you want to update the value from a custom handler then you can use setFieldValue
for setting the field value.
Working Code - CodeSandBox 1
Upvotes: 2