Search code examples
reactjsreduxaxiosformikdynamicform

Formik - Update initial values after API call


I'm getting my inputs dynamically from an API call based on a change in select input, but when I try to add to the initial values of Formik, it always gives me an error ...

Warning: A component is changing an uncontrolled input of type text to be controlled.

And it doesn't help if I set enableReinitialize={true} to Formik.

However, if I generated the inputs from a local JSON or object, the error goes away.

What am I doing wrong here ...

https://codesandbox.io/s/test-dynamic-inputs-with-formik-xr9qg

The form submits fine though.


Solution

  • If anyone is facing the same issue, I just found the solution ...

    You have to set value={field.value || ''} in the input inside the TextInput component or whatever type you're using in order to fix this issue.