You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
zod's default() only works with undefined and not null, which this library perfectly mimics. Zod Sandbox Example
Thanks to catch() on the other hand, it is possible to have a default value when validation fails. But Valibot seems to not have catch().
It is one of the most useful functions of zod (atleast to me) and I use it a lot. Especially with react, where I want the ensure the app always has certain pieces of data.
Thanks to the simplicity of Valibot is was able to quickly write a catch method.
This method could also be called fallback. I originally called it that, but to stay true to zod's naming I changed it to Catch, just not catch (reserved word).
The text was updated successfully, but these errors were encountered:
I read some of the performance issues and the proposed changes to move away from error throwing to some form of context being passed around, might make this function more complex. Should still work very similar though, if the previous validation issues are not passed down, only up. Catching those would be almost the same.
zod's
default()
only works with undefined and not null, which this library perfectly mimics. Zod Sandbox ExampleThanks to
catch()
on the other hand, it is possible to have a default value when validation fails. But Valibot seems to not havecatch()
.It is one of the most useful functions of zod (atleast to me) and I use it a lot. Especially with react, where I want the ensure the app always has certain pieces of data.
Thanks to the simplicity of Valibot is was able to quickly write a catch method.
Sandbox with usage examples
npm run fallback
This method could also be called fallback. I originally called it that, but to stay true to zod's naming I changed it to Catch, just not catch (reserved word).
The text was updated successfully, but these errors were encountered: