Replies: 5 comments 6 replies
-
I'm wondering the same exact thing. It'd be great if by changing the search param, loader function will be triggered automatically. One way of solving this is for the time being, would be pulling a data fetching library like react query, passing the search params from useSearch into useQuery to trigger a refetch. |
Beta Was this translation helpful? Give feedback.
-
This is a quote from react router website:
Specifically route's path. So i think it is better react router add a flag to useNavigation's navigate function to force router reload required loader. I am facing this problem in my react app and I had to add additional lines of code to work around this. |
Beta Was this translation helpful? Give feedback.
-
I'm evaluating TanStack Router as a potential replacement for the React Router we currently use, and I have run into this issue too. React Router calls loader when search parameters change, but TanStack does not 😔. This is my workaround, but I think it should be an option on the route or the useNavigate hook. //HACK: force loader to run when search params change
const search = useSearch();
const router = useRouter();
useEffect(() => {router.invalidate()}, [search, router]); |
Beta Was this translation helpful? Give feedback.
-
As of the latest version, it’s impossible to use search params in a loader without passing them through the loader context. Anything you pass through the loader context is watched for changes. When they change, your loader will rerun. |
Beta Was this translation helpful? Give feedback.
-
Is there any feasible way of doing this, short of navigating back to the same route with some kind of random search param to essentially force rerunning of the loader? My use case is essentially adding an item to a list, and I'd prefer not to have a full postback or duplicating the loader call on the page itself. edit const navigate = Route.useNavigate();
...
const submitForm = () => {
navigate({ to: '.' });
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm trying to refresh loader data after navigation with new search params by using hook useNavigation. Unfortunately, it was not possible to update the loader data in this way. Perhaps there are other ways to refetch data?
Beta Was this translation helpful? Give feedback.
All reactions