Lots of talk about React suspense today. I’m very excited about it.

However, I feel like the patterns I’ve seen in #ReactQuery (and friends like SWR) have alone been more transformative for my own dev process and users and have even prepped me for suspense in a lot of ways.
Of course, Suspense isn’t out yet, and the ecosystem will likely experience a smash of collective inovation around it when it comes out. That’s the exciting part. But what I feel like I’m starting to realize after playing around with it is that in the end,
The biggest thing that suspense is going to do for me is just one thing: avoiding that flash of loading/placeholder for newly mounted components. Suspense doesn’t fetch, it doesn’t codesplit, it doesn’t preload for you and it doesn’t cache for you.
It’s really only about smoothing out the experience of moving from state to state without seeing a loading placeholder. And I am all for it! I hate those loading flashes.

But if I’m being honest, I think caching and prefetching are WAY more important than that UX quirk.
The fact that suspense will depend on data loading, prefetching, caching, etc to be used to its fullest potential is the most curious piece of it all. We’re all waiting for suspense to happen. It will. But then what? At that point everyone will be reaching for three things:
1. Automatic code and data splitting.

2. The ability to prefetch that code and data in a reliable way.

3. Data caching layer.
I’m working from the bottom up with #ReactQuery. And already getting so many benefits without even thinking about suspense or code splitting. I’m also using Next.js from the top down to take care of as much code/data splitting and prefetching when I need it.
Which brings me to my point: I don’t feel like I’m really missing out on that much right now. The occasional flash of loading placeholder 🤷‍♂️ I can live with that. Heck, if it’s that important, prefetch it earlier! Don’t need suspense for that.
You don’t need anything more than we have already to start caching, prefetching, code/data splitting, etc.
All concepts that have been possible even before things like hooks rocked our world. You don’t need to wait for suspense to make your UX faster and better. In fact, you shouldn’t. Take advantage of this time waiting for it and get a step ahead of it.
Future you will be grateful. And you’ll be surprised at how far some caching and prefetching go. So far that, like me, you might forget about suspense for now, because you won’t need it nearly as much. Then when it comes, you’ll be even more ready!

#TanStack #react #myTEDtalk
You can follow @tannerlinsley.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: