practiceintermediate
Form with validation
A registration form with three fields (email, password, confirmation). Model the changes and validation with useReducer: each named action, pure reducer, errors derived on each transition.
Objectives
- 1.Reducer with actions
change,blur,submit - 2.State: { values, touched, submitted } — errors are derived in render, not stored
- 3.Validate email (format), password (≥ 6 chars), confirm (equals password)
- 4.Only show errors for a field when it
stouched' or after submit - 5.Submit disabled if there are errors — but computed in render, not stored
- 6.On successful submit, show a
sentstate
your code
Hint
Don't store 'isValid' in state — derive it from errors. Errors are recalculated in the reducer with a pure validate(values) function.
Related concepts
Was this helpful?
Sign in to give feedback
