-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
Description
Bug report
Current Behavior
When trying to setFieldValue within onPaste callback prepends the field value instead of replacing it.
Expected behavior
setFieldValue should replace the field value
Reproducible example
The templates are outdated (very old React/Formik versions) I couldn't get them to work without refactoring the entire thing.
This is the code I'm using
onPaste={async (event: ClipboardEvent<HTMLInputElement>) => {
const reg = /:(?<port>[0-9]+)/
const valueArray = event.clipboardData.getData('text/plain').split(reg);
if (Number(valueArray[1])) {
setFieldValue('url', valueArray[0]);
setFieldValue('port', valueArray[1]);
}
}
Your environment
Software | Version(s) |
---|---|
Formik | 2.2.9 |
React | 17.0.2 |
TypeScript | 4.4.2 |
Browser | Chrome latest |
npm/Yarn | Yarn |
Operating System | Ubuntu 20 |