Formik: Custom component without <input />

Created on 12 Dec 2017  ·  3Comments  ·  Source: formium/formik

Is it possible to use Formik for react components that don't rely on html <input /> field?

My component is a custom selector that relies only on <div> and <span> elements.
Right now Formik event handler assumes the presence of event.name, which is fine for input components, but for div elements I can't set name on them because it's not valid.

Formik is really great for us, but this is quite a blocker right now.
How should we handle this?

Thanks

Most helpful comment

Use setFieldValue, it’s built just for this

All 3 comments

So far I have managed to work around it, but it's really hackish.
Here's my solution:

(e) => {
  e.target.name = "nameOfThePropIWantFormikToUpdate"
  e.target.value = "valueOfThatProp"
  this.props.handleChange(e)
}

Use setFieldValue, it’s built just for this

Thank you so much.
Formik is great

Was this page helpful?
0 / 5 - 0 ratings

Related issues

giulioambrogi picture giulioambrogi  ·  3Comments

green-pickle picture green-pickle  ·  3Comments

sibelius picture sibelius  ·  3Comments

najisawas picture najisawas  ·  3Comments

jordantrainor picture jordantrainor  ·  3Comments