State Management · Senior · Question 60 of 75
Why validate state read from the URL (search params) with a schema?
const filters = FiltersSchema.parse(Object.fromEntries(searchParams));- ✓Correct answer: URLs are user-controlled input; parsing with defaults prevents crashes and invalid states from hand-edited or old links
- 2Search params are always typed correctly by the router
- 3Schemas compress the URL
Explanation
A schema (e.g. Zod) coerces strings to numbers, applies defaults and rejects garbage. Treat the URL like any external API.