zodValidator confusion #3476
Answered
by
schiller-manuel
michael-wolfenden
asked this question in
Q&A
-
I'm not understanding the difference between using const productSearchSchemaCatch = z.object({
page: z.number().catch(1),
filter: z.string().catch(""),
sort: z.enum(["newest", "oldest", "price"]).catch("newest"),
});
export const Route = createFileRoute("/")({
component: App,
validateSearch: zodValidator(productSearchSchemaFallback),
}); vs const productSearchSchemaFallback = z.object({
page: fallback(z.number(), 1).default(1),
filter: fallback(z.string(), "").default(""),
sort: fallback(z.enum(["newest", "oldest", "price"]), "newest").default(
"newest",
),
});
export const Route = createFileRoute("/")({
component: App,
validateSearch: zodValidator(productSearchSchemaFallback),
}); Functionally, they appear to be equivalent. The docs state
However I'm not seeing that either. I have an example below that shows both scenarios: |
Beta Was this translation helpful? Give feedback.
Answered by
schiller-manuel
Feb 18, 2025
Replies: 1 comment 3 replies
-
the datatype is |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
michael-wolfenden
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the datatype is
unknown
with justcatch()
: