React hook to extract errors?
I got the following hook, I'm not sure how to properly take the message for StandardSchema errors, any insight would be great! We basically always use either string OR zod for validators.
2 Replies
stormy-goldOP•6mo ago
In my form as an example, sometimes standard schema returns errors in a structure like:
Other times:
I think depending on if the item is within an array it'll nest it in another array? Confused if there's a sort of handler already for this?
This is what I'm doing now, seems to be working fine though not sure if there's a different recommended way:
xenial-black•6mo ago
your approach sounds very similar to ours. I recommend using a type predicate for the message property:
looking back on this snippet, there seems to be an unnecessary check since the second condition overlaps the first