Closed stellarhoof closed 5 years ago
Just summarizing our off-github conversation: I'm not sure I see the value in this because it's trivial to compose fields (just use object spread) and submit methods are just functions (so you can compose them as you would other functions). The net savings would likely be a few lines of code but would come at the cost of introducing new concepts and API surface for form composition (instead of just regular functional/object composition).
With that said, we definitely should at least create a canonical example of doing this, even if there's no official API (like how focusing a field has a demo, but no underlying actual API is needed in this library).
Say you've got a couple forms
form1
andform2
like the example in the readme:There's currently no way of composing them. Such composition should:
submit
s generically, since we can have a subform that depends on results from previous subforms.Those are the harder ones. The semantics of composing
reset
,validate
, etc... are trivial. We just iterate through the composed forms and call those methods in order.