-
I'm using Formik to build up a hierarchical data structure dynamically, with components that are contingent on user choices and input. The form is similarly hierarchical and dynamic and matches the underlying structure as both are built. This works pretty well, but it is somewhat rigid. For instance, if I want to support input of different types of data at the same point in the structure, I need fields that reach into different parts of an object in the structure. But coordinating these changes is challenging. What I'd like to have (for any given field/widget) is a transformation between the data in the field and the value stored in the field state. That is, I'd like to be able to specify a function f and its inverse g, so that Reading this, I see that it is a bit abstract, so let me try to sketch a schematic example. Imagine that at some point in the form, the data looks like a nested array How would this best be done with Formik? In any case, I hope I'm being clear, and if not, let me know how I can clarify. I'd appreciate any ideas or any possibilities that I've missed. Thanks, and thanks for Formik; it is really terrific. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
To further clarify, here's the kind of thing I'm trying. I'm thinking that this pattern can be packaged into a
where I've borrowed liberally from Formik here ( For How does this look? Is there an easier approach? |
Beta Was this translation helpful? Give feedback.
-
Formik v3 will have parse and format props. You can test them out using version Here you would do
|
Beta Was this translation helpful? Give feedback.
Formik v3 will have parse and format props. You can test them out using version
formik@next
. I think they let you do exactly what you're requesting.Here you would do