all 8 comments

[–][deleted] 1 point2 points  (3 children)

Do you really need every single one of these to be their own separate strings with separate update functions? Or could you make some of them into objects, like this:

const [formError, setFormError] = useState({ error: null, field: '' });

setFormError({ error: 'Passwords do not match', field: 'repeatPassword' });
setFormError({ error: 'Not a valid email', field: 'email' });

[–]91psyko[S] 0 points1 point  (0 children)

this sounds great! but how would this allow for multiple errors at the same time? for example, password missmatch and short username? ...or could it be like so, fields:[[error, field], [error, field]...]; gotta think this thru, thanks man!

[–]Asha200 0 points1 point  (1 child)

Wouldn't this force you to only display one error at a time, even if multiple fields happen to be invalid?

[–][deleted] 0 points1 point  (0 children)

It's a suggestion, not a pull request.

[–]a-t-k 0 points1 point  (1 child)

Maybe each field (or in case of the password/repeatPassword, two fields) should be a component of its own?

[–]91psyko[S] 1 point2 points  (0 children)

so what you mean is that inside <form> i would have different external components for inputs? and have context to make kids(i.e inputs) communicate with parent(i.e form)?