What is the recommandation for composition, AppForm provider and DOM form element?
Hi TanStack team!
Context:
• createFormHook to compose our UI components into the form hook.
• createFormHookContexts to get formContext and fieldContext for our provider/consumers.
• To access form.handleSubmit from the hook, I pass our DOM form component to formComponents.
Questions:
• To get handleSubmit from the hook, I pass TanstackForm via formComponents. But I still have to wrap form.TanstackForm inside form.AppForm (the provider). This feels like I’m duplicating the “form” constructs: a provider (AppForm) and the DOM form (TanstackForm).
• Is this the recommended pattern with createFormHook + createFormHookContexts? Or is there a way to have a single top-level form element that covers both the provider and the actual <form> DOM element?
• In other words, can/should form.TanstackForm also provide the context so we don’t need an extra form.AppForm wrapper? Or is there another composition approach you recommend to avoid this duplication?
Any guidance or examples would be greatly appreciated. Thanks!
2 Replies
jolly-crimson•6d ago
yes, because not everything with context is bound to the DOM
for example, submit button form components can be outside of a DOM form element, as long as the
form prop points to its id
you can also have logic-based components like a navigation blockerconscious-sapphireOP•6d ago
@Luca | LeCarbonator thank you very much for the quick answer 🙂