🤯
진짜 간단함
if문 쓰듯이 폼 플로우 짜면 됨. 복잡한 상태 관리는 라이브러리가 알아서.
다단계 폼 만들 때 이런 고민 해본 적 있죠?
Mozard는 JavaScript Generator를 써서 이런 문제들을 해결합니다. 그냥 함수 쓰듯이 자연스럽게 쓰면 됨:
*do(step) {
const profile = yield* step("profile", ProfileForm, {});
// 미성년자면 보호자 동의 받기
if (profile.age < 20) {
const consent = yield* step("parentConsent", ParentConsentForm, {});
return { profile, consent };
}
// 성인이면 바로 환경설정
const prefs = yield* step("preferences", PreferencesForm, {});
return { profile, prefs };
}
네, 이게 다입니다. if문 쓰듯이 쓰면 되고, 뒤로 가기도 알아서 되고, 타입도 안전함.