1. 17
    Reveal Suspense Components in Order with SuspenseList's revealOrder Prop in React
    1m 57s

Reveal Suspense Components in Order with SuspenseList's revealOrder Prop in React

Michael Chan
InstructorMichael Chan
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 years ago

revealOrder is one of SuspenseLists configuration options. It can be undefined, together, forwards, and backwards.

  • undefined (default): reveal children as suspenders resolve
  • together: reveal children together, once all suspenders are resolved
  • forwards: render children from top to bottom, indifferent to suspender resolution order
  • backwards: render children from bottom to top, indifferent to suspender resolution order

Instructor: [00:00] The Suspense list reveal order prop has a number of options -- forwards, backwards and together. Let's see what they do.

[00:09] We've seen previously that, by default, Suspense list will render the first available Suspense components. If we hit refresh again, we'll see the list of Pokemon come in first, followed by the Pokemon.

[00:25] However, when we pass in the prop reveal order, and use the value together, it works like a promise.all. Anything that is in here, any of these suspense components, we're going to wait for all of them to resolve before we show anything. Let's watch that again, waiting for both of these to come back. Then we show it all at once.

[00:48] Because we're controlling the speed of these responses, we know that this one comes in faster than this one. Let's change this to backwards first.

[01:02] We'll always see the bottom one resolve first or see them resolve together. We saw the first case, but let's verify that they'll show together if this promise resolves second. Jump into our API and just switch these values.

[01:20] This one's now 1.5 seconds, and this one is 3 seconds. Now we'll see that they come together, because backwards always tries to resolve the bottom Suspense component first. Because it takes longer, they render together.

[01:36] We can see this effect in reverse if we try out forwards. Now the individual Pokemon resolves first, and then the second Suspense component when it resolves. I find that in most cases, forwards or together is what I want to use.

~ 20 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today