When to use Suspense vs startTransition? #94
Replies: 2 comments 3 replies
-
Quoting a comment here as it seems more relevant. Especially this one:
I felt like I had a wrong mental model, because I thought I would be using
|
Beta Was this translation helpful? Give feedback.
-
Hey! That’s a great question! These two APIs are designed for different use cases and can absolutely be used together. There are two kinds of scenarios at play:
For example, consider an App with a Homefeed and a Profile page. The app is wrapped in a Suspense boundary with a loading spinner fallback. When you first load the Homefeed, we will initially render a loading spinner while the page waits for data. If you then navigate from Homefeed to Profile:
Because So in the example above, if you have a Suspense boundary around your friends list in the Profile page, users can view the rest of the page while the friends list loads. |
Beta Was this translation helpful? Give feedback.
-
I see that some examples shared in the discussions have UI intensive tasks, and therefore marked in
startTransition
, such asthis example by Swizec.
Are there use cases where it makes sense to put a fallback component in Suspense vs marking UI updates in startTransition? Is there a best practice approach of choosing one vs the other or should these be used together?
In an API heavy app, eg: infinite image scrolling app such as Instagram, how do we determine if a task should have a fallback component or be wrapped inside
startTransition
? Example codesandbox hereBeta Was this translation helpful? Give feedback.
All reactions