Turn #11 into a section in the docs (Note: handleChangeValue has since been renamed setFieldValue)
## Handling arrays
There are a few methods to handling arrays with Formik.
### Custom component + `setFieldValue`
https://github.com/jaredpalmer/formik/issues/11#issuecomment-312489299
### Flatten and Prefix
https://github.com/jaredpalmer/formik/issues/11#issuecomment-312449018
Related: #59 #58 #40 #11 #116 #147 #151
In the mean time, does anybody have any clear, working examples anywhere of either of these two approaches?
Agree, a gist would be great! And BTW formik is really nice! thanks
I really liked Formik at start, it is really good with all the features and best part no redux or unnecessary complexity, But now when it comes to create nested and handling arrays poor documentation is a deal breaker for me.
My json is not that complicated but still I am unable to figure out the best way to create the form using Formik. Approach of transforming the json keys and the transforming them again on submit doesn't sound less code to me. And other approach of creating child form component, I am not sure how to manage form state with that, there is no working example.
Nested approach also doesn't work for me for the below use case
json{
{
"trips": {
"id": 123,
"name": "test"
},
"offers": {
"id": 123,
"name": "BOGO"
},
"travellers": [
{
"name": "Andrew",
"age": 21,
"sex": "M"
},
{
"name": "Martin",
"age": 22,
"sex": "M"
}
]
}
I had to move to React Form, their documentations is really good as you can see here
https://react-form.js.org/#/nested-form
@gauravarora91 You are right documentation is poor but still formik is powerful. @jaredpalmer thank you for you library and if you need me to help you writing example feel free to ping me.
I have not documented arrays because the feature is not yet complete 馃槀
Any documentation on dynamic fields? I really don't know how to proceed with formik in this case.
For anyone ending up here. Formic has a <FieldArray /> component that solves this! https://github.com/jaredpalmer/formik#fieldarray- 馃槉
now docs are here https://jaredpalmer.com/formik/docs/api/fieldarray
Ross Bulat's example of dynamic use of FieldArray, as a codesandbox: https://codesandbox.io/s/formik-fieldarray-rossbulat-6mqfw
Codesandbox of example from fieldarray docs. Changed slightly to ALWAYS show "Add Friend" button at bottom of list: https://codesandbox.io/s/formik-fieldarray-from-docs-p4chd
Most helpful comment
For anyone ending up here. Formic has a
<FieldArray />component that solves this! https://github.com/jaredpalmer/formik#fieldarray- 馃槉