Can't Use `useSearch` in Reusable Component Across Multiple Routes
I'm having trouble using useSearch in a reusable component when working with multiple routes in a TanStack Router project. Here's a breakdown of the issue:
Code Example
The Reusable Component:
The Route:
The Problem:
When I use this setup, I encounter the following error:
It seems that the useSearch hook cannot find the route
/ _protected/testing/
in this context. This makes the Pagination component unusable across multiple routes.
What I Expect:
The Pagination component should work seamlessly with different routes, as long as the search params for that route are properly validated and accessible.
Questions:
1. Is this the intended behavior for useSearch with the from option?
2. If so, what's the best practice for creating reusable components like Pagination that rely on route-specific search params?
3. Is there a workaround to dynamically determine the current route or make this reusable component work with multiple routes without duplicating code?
Any insights, suggestions, or alternative patterns would be greatly appreciated! Thanks in advance. 🙏0 Replies