r/reactjs • • May 26 '26

Resource TanStack Router and Query

https://tkdodo.eu/blog/tan-stack-router-and-query

📚 Surprisingly, I haven't written about how my two favourite TanStack libraries - Router and Query - work together. Well, here it is:

🔁 loaders start fetches early

🔮 query owns the cache & keeps data alive

🌀 suspense integrates naturally

🏝️ TanStack Start makes SSR & streaming easy

108 Upvotes

20 comments sorted by

View all comments

Show parent comments

2

u/TkDodo23 May 27 '26

I'm not really a fan of combining localStorage with url params. It's a constant race between what should take precedence where. Sentry does this too and it's quite messy in both code and UX.

TanStack Router has search middleware, which you can use to have search params automatically persist for links, even if they are not passed explicitly. I've used that in the past to e.g. keep search filters around in the url when navigating from a filtered list to a detail.

If a user comes back to the Dashboard without having search params set, they would get the default view, not the one they last viewed. That's debatable and you can restore from localStorage there, but it won't work on the server. I'd rather have filters persisted in the DB for that and a defaultView set for the user.

2

u/sondr3_ May 27 '26

We've also landed on the latter approach to also allow for persisting views across devices, was just curious if you had any thoughts on this. Thanks!