Problem: React Router’s useSearchParams is clunky, and not type safe


Problem: React Router’s useSearchParams is clunky, and not type safe. Values are always returned as strings, and there’s no type-safe protection for writing values.

Two solutions:

1. Wrap React Router’s searchParams in a custom hook that validates params via Zod.

2. Consider Tanstack Router instead. It has a strongly typed search params API with built-in validation support.

How I do 1:

View original on X