A disadvantage of this approach is that you can't really use the Formik's <Field /> component. And for each input field, you need to write a lot of unwanted and repeating code, which I have marked in red.
It is important that this component is nested under the <Formik> component so it can access the necessary properties inside the useField() hook. You can provide additional styling properties to theFormikTextField component similarly as to the original TextField component.
A disadvantage of this approach is that you can't really use the Formik's
<Field />component. And for each input field, you need to write a lot of unwanted and repeating code, which I have marked in red.Thanks for pointing this out, I haven't used
<Field/>component before so I will check it outYou can easily use the useField hook and transfer the field object as props to the material-ui TextField.
Take a look at this :)
jaredpalmer.com/formik/docs/api/us...
Hi! Giacomo, i don't get how to compose usefield hook with material-ui TextField. Can you write a quick example ?
Hello, I have created an example of how to use an useField hook with material-ui TextField.
Below is a simple FormikTextField component, that can be reused across the whole application.
It is important that this component is nested under the
<Formik>component so it can access the necessary properties inside the useField() hook. You can provide additional styling properties to theFormikTextFieldcomponent similarly as to the originalTextFieldcomponent.