Design Rationale: form.ComponentName vs. Direct Import + Context for Pre-bound Components
#1441
Replies: 1 comment
-
|
Thanks for writing up this question because I had the same one. The current design also breaks IntelliJ's go-to-implementation because it removes the static binding between I would also like to understand why the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi TanStack Form team,
First off, thanks for the great work on TanStack Form! I've been exploring the composition patterns using
createFormHook, specifically pre-bound field and form components.I understand from the docs and source code that components registered in
fieldComponents/formComponentsrely on context provided byAppField/AppForm(usinguseFieldContext/useFormContextinternally) to function correctly.My question is about the recommended access pattern shown in the docs:
I've confirmed by looking at the source code that
createFormHookattaches the registered components (likeSubscribeButton) as properties onto theforminstance returned byuseAppForm.However, it seems functionally possible to achieve a similar result by directly importing the component and relying on the context provided by
<form.AppForm>:Assuming
SubscribeButtoncorrectly usesuseFormContext, this second approach seems like it could work functionally.My question is: What is the specific design rationale or the key advantages of using the
form.ComponentNameaccess pattern over the direct import + context reliance approach?I can see potential reasons like:
createFormHooksetup) is used.form.accessor.<form.Field>/<form.Subscribe>.Are these the main drivers, or are there other functional differences or considerations I might be missing? I'm trying to fully grasp the intent behind this specific API design choice.
Thanks for any insights you can share!
Beta Was this translation helpful? Give feedback.
All reactions