Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
[Form 스키마 관리 전략에 대한 고민]
안녕하세요. form이 매우 많은 프로젝트를 진행중입니다. 스키마와 타입을 지정할 때 좋은 방법이 없을까 고민이 있어 의견을 구합니다.
현재 상황
TypeScript + React 프로젝트
Form 관리: react-hook-form + zod
API 통신: TanStack Query
핵심 이슈: 동일한 필드가 조회/생성 시에는 optional이지만, 수정 시에는 required인 상황
현재 고려중인 해결 방안
A. 스키마 분리 전략
기본 스키마를 만들고 용도별로 extends
각 스키마를 전용 hook에서 사용
단점: 스키마가 깊거나 차이가 많을 경우 유지보수 부담 증가
B. 단일 스키마 + 런타임 검증
모든 필드를 optional로 설정
하나의 스키마를 공유하고 hook/서버/DOM에서 추가 검증
단점: 검증 로직이 분산되어 코드 추적이 어려움
C. 다른 접근 방식이 있을까요?
더 나은 해결 방안이 있다면 공유 부탁드립니다.
25 votes ·
Beta Was this translation helpful? Give feedback.
All reactions