Fomik does not validate field onPaste, unless you click outside of field (blur)

Ben Grunfeld
2 min readMay 29, 2023

Recently I had a nasty bug when using Formik with React and Next.JS.

When you added a contact from Android, a new value would be pasted into an input field. Unfortunately Formik did not realize that this was happening, and did not validate the field. We needed validation to run on paste.

tl;dr — my mega-hacky solution:

const handlePaste = () => {
setTimeout(() => {
emailRef.current.childNodes[1].firstChild.blur()…

--

--

Ben Grunfeld

I’m a Front End Engineer who loves React, NextJS, and GraphQL. Looking for a developer in #Israel? Contact me at: https://www.linkedin.com/in/bengrunfeld/