Best practice for sharing validation logic across reusable components in TanStack Form
I'm investigating adopting TanStack Form for form composition within our React application. I've successfully composed a field component using TanStack Form, but I'm struggling to understand the best approach for including validation logic with reusable components.
For example, I have a complex use case involving a coordinate input form (it allows text input, as well as selection via clicking on a map). Currently, the validation logic is built directly into the React component itself. Each time a user changes the value, it validates whether the coordinate is valid.
I want to move towards the TanStack Form composition approach, but I'm confused about how to share this validation logic effectively. It feels like keeping the validation inside the coordinate input component goes against the recommended form-driven validation approach, where validators live outside components and are registered via the form configuration. However, if I remove the validation from the component, then every time someone uses this coordinate input elsewhere, they would have to remember to add the specific validator themselves.
My questions are:
What is the recommended pattern for sharing complex validation logic across multiple forms when using reusable input components in TanStack Form?
Should the coordinate validation remain embedded within the component, or is there a way to tie it to the component by default while still following TanStack Form's validator registration model?
How do others manage validators that are intrinsic to the concept of a field (e.g. a coordinate input that must always validate as a coordinate) without duplicating validator setup across forms?
Any guidance or examples would be greatly appreciated to help structure our implementation cleanly.
Thanks in advance!