Is there a way to invalidate a query from a tanstack start server function
I'm using react query with tanstack start and I am redirecting from the server function straight but I need to invalidate the query I don't know if that is possible or I would need to stop redirecting from the server function completely
6 Replies
other-emerald•8mo ago
Show some code?
exotic-emeraldOP•8mo ago
I have this on the frontend
The server function
The route I am redirecting to has a query before I redirect is there a way I can invalidate the query on that page so it refetches or will I need to redirect on the frontend?
other-emerald•8mo ago
Wrap the server function
const $yourBoundServerFn = useServerFn(yourServerFn)
The use that
That will handle the redirect without killing your side effects
exotic-emeraldOP•8mo ago
Since I'm redirecting will the onSuccess run
That's the issue I'm worried about since I'm redirecting from the server function will the onSuccess for use mutation run at all?
other-emerald•8mo ago
It should
Redirects are handled by that hook and allow the happy path to continue
Yep
other-emerald•8mo ago
GitHub
router/packages/start/src/client/useServerFn.ts at 2d182c74412dad71...
🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering. - TanStack/router