— Profile picture
9 Jun, 9 tweets, 3 min read
Since React 18 is coming i'm compiling some tweets exploring suspense, a groundbreaking new feature.

Suspense allows components to handle async tasks, while the parent control loading, errors and fallbacks. It essentially solves async in front end.

Here are some use cases →
Example #1 — You load an async asset (fetch, wasm, parsing, workers, ...). When it's finished you want to execute a specific action, for instance zoom in.

Since <Model /> is async and <ZoomIn />, which is not, share the same suspense boundary, <ZoomIn /> will not execute before <Model /> is ready.

This is literally all you have to do, drop a component in. ✨
Example #2 — One component is async, while the other needs to operate upon the result of it.

Same thing, if both share the same suspense boundary useEffect in the operating component is guaranteed to be able to access the async reference.

Example #3 — You want fallbacks. This would be hard already, but imagine going through variants, where you load a lesser thing first before switching to hi-res. Sketchfab does that for instance .

This is trivial with suspense because you can nest it.

Example #4 — What if you load something but you want to hold on to the current thing on screen, you want users to be able to continue interacting with it until the new thing comes in.

With suspense you can define transitions that make this so easy.

Example #5 — You want to cache and re-use assets.

This is not even an afterthought, because suspense is built on caching. How it caches is up to the layer that controls the suspense.

There might be more. But as you see, the feature can do far more than fetching data. There are some examples here that remind me of when i had to struggle with C/C++ and threads and how hard it was to do certain things, and now i can just lego compose async. 🧙‍♂️

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with

— Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @0xca0a

8 Sep 20
we are releasing JŌTAI today github.com/react-spring/j… 🎉 this is @dai_shi 's take of the atomic state model. quite similar to recoil but focusses on a small api surface w/ simpler albeit equally powerful atoms and derived state. jōtai is 100% ready for concurrent mode and suspense
in its simplest form think of it as a global replacement for useState. in scale you can create complex transforms and relations between state atoms. see it in action here: jotai.surge.sh or try it out on codesandbox: codesandbox.io/s/1w52w
you might be wondering why so many libs come from "react-spring". started with an anim lib, turned into a gh-org, and it's been more like a collective recently (say hello discord.gg/ZZjjNvJ), there are 25 devs working for it atm. full rebrand and exciting news coming soon.
Read 4 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(