Skip to content
Advertisement

React Formik : how to use custom onChange and onBlur

I’m starting out with the formik library for react, and I can’t figure out the usage of the props handleChange and handleBlur.

According to the docs, handleBlur can be set as a prop on a <Formik/>, and then has to be passed manually down to the <input/>.

I’ve tried that, with no success : (I’m keeping the code about handleBlur for more clarity)

JavaScript

What is wrong with this approach ? How are handleBlur and handleChange actually supposed to be used ?

Advertisement

Answer

You’ll need to remove the first handleBlur from Formik as blur event is only valid on the field level and do something like the following in your Field element:

JavaScript

See https://github.com/jaredpalmer/formik/issues/157

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement