TanStackT
TanStack5mo ago
10 replies
dangerous-fuchsia

Search params with zod

I have read the search params guide many times now and I think I'm misunderstanding something.

Our scenario is that we have let's say 2 routes (bookings list and booking details) that have the functionality to cancel the booking. When a user clicks such link or button, we add a search param in the url to handle the open state of the modal like confirmation sheet (that includes some other cancel related functionalities), we do the same for the unassigning the worker from the booking use case. Again both routes have this button and link and add a search param to show the modal like side sheet to handle and confirm the unassignment details and to confirm the action.

Where I get really confused is how to set this up in a typescript loving manner with validateSearch using zod. Do I add for both sheets the params required to use the sheet? And make them both optional? Or the whole schema is partial? And how to handle the useSearch part as it would require a from param but which route?

As you can read, I don't quite grasp how this is supposed to be set up. Any pointers would be greatly appreciated
Was this page helpful?