T
TanStack5mo ago
stormy-gold

Handling of failed search params against zod schema

I am looking for a good pattern to handle errors associated with incorrect search params not matching up with zod schema. Does tanstack provide a way of handling these search params. Like fixing or stripping out them if they fail against the schema?
3 Replies
stormy-gold
stormy-goldOP5mo ago
found it in the docs: In the above example, we used Zod's .catch() modifier instead of .default() to avoid showing an error to the user because we firmly believe that if a search parameter is malformed, you probably don't want to halt the user's experience through the app to show a big fat error message. That said, there may be times that you do want to show an error message. In that case, you can use .default() instead of .catch().
eastern-cyan
eastern-cyan5mo ago
There is a @tanstack/zod-adapter provides a fallback to make sure the types are correct
exotic-emerald
exotic-emerald5mo ago
I'm looking for a similar thing but wanted to redirect the user back if the schema fails. still haven't figured out a better way of doing this without manually calling the schema again in beforeLoad

Did you find this page helpful?