T
TanStack2y ago
absent-sapphire

Possible to use preloading without suspense?

I want to be able to pre-load some data when a use hovers over a link, however I do not want the loader function to cause a suspense trigger, is that possible? For context, I have a page in my app that shows some data in a Grid. The grid component already handles showing a loading icon when the data isn't fetched yet. I want to use this native loading functionality instead of having the whole route suspend.
2 Replies
fascinating-indigo
fascinating-indigo2y ago
Can I assume you are using an async state manager like Tanstack Query? If so, then in the beforeLoad or loader callback(s), you can call the prefetchQuery method without awaiting its response. That way it instantly resolves. If not, and you are actually USING the loader to load and store data, then you'd be stuck waiting for it to resolve since that would be the behaviour defined.
absent-sapphire
absent-sapphireOP2y ago
Yes, I'm using Tanstack Query. I'll give prefetch query a try. From the documentation I was under the impression that the loader function itself is what was causing the suspense to trigger, rather than the ensureQuery call. Thank you!

Did you find this page helpful?