T
TanStack3y ago
like-gold

Link searchReducer provides unvalidated search values

Hi, I am using zod to validate search params, just like in the example in the docs. When I visit my route with no search provided, I expect it to use the fallback of page=1 behind the scenes. My react-query useQuery dependant on useSearch receives the correct page value. Router devtools shows page=1. But when I use a <Link> with search={(prev) => ({page: prev.page + 1})}, page shows a type of number. But such a link results in page=NaN. It seems like prev.page provided here is not the validated param and it is giving me the original NaN. In the attached image I am using (prev.page ?? 1) + 1 to avoid this issue but it seems like it should not be necessary given that it shows prev.page will have a type of number. When I use <Link search={{...search, search.page + 1}}> (using search from useSearch), it goes to page 2 correctly but it also litters the url with all of the fallback values. What's the correct pattern to use here, to simply add 1 to page, and only include other search params if they are non-default ? Thanks
No description
No description
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?