Why form validation logic belongs in the domain layer, not your UI components
A frontend developer argues that delegating validation logic to libraries like React Hook Form, Zod, or Yup causes business rules to scatter across the codebase with no single source of truth. The problem typically surfaces months later when the same rule must be applied across multiple contexts — creation, editing, or bulk imports — and ends up written slightly differently each time. The author proposes treating an invalid field as a domain rule rather than a UI state, moving validation into named, testable units independent of any component. Using VIN number validation as a concrete example, the approach aims to make rules reusable, independently testable without mounting React components, and portable to the backend without rewriting logic. The article critiques not the libraries themselves, but the common practice of delegating domain decisions to tools designed only to wire inputs to state.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in