How does react Suspense work?

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ธ.ค. 2024

ความคิดเห็น • 23

  • @malhar016
    @malhar016 7 หลายเดือนก่อน +8

    I really liked your way of "going through -> asking -> thinking -> assuming -> and understanding it on the go"... type of approach. Sometimes I feel overwhelming by other know-it-all kind of videos, which makes you feel small about not knowing what they know very easily. Keep it up dude.

  • @skittlznt2611
    @skittlznt2611 ปีที่แล้ว +7

    I literally came to Utube after reading that exact article and walking away a bit confused. Funny that I landed on this video explaining it. I love your disorganized style of teaching btw. It's refreshing to see someone ask the same questions that are popping around in my head.

  • @sachinahya7502
    @sachinahya7502 2 ปีที่แล้ว +27

    The main benefit of Suspense is that it helps write simpler components that don't care about the network status of their data, they can just assume the happy path where the data is always available.
    The Suspense fallback can be triggered by any of its deeply nested children which gives you more control over layout shift, compared to having lots of child components each rendering their own fallback.

  • @alessiomichelini4171
    @alessiomichelini4171 2 ปีที่แล้ว +10

    Btw I don't set the success as it will fallback to default anyway, what you want to catch is if you have either an error or pending, and throw an error with those, everything else should just return the response, because Suspense what it does it's just listening if a block of code is throwing any error, if it throws it handles as a loading state, if it doesn't it means that the code is ready to be shown

  • @alessiomichelini4171
    @alessiomichelini4171 2 ปีที่แล้ว +5

    I'm glad you liked my article, and thanks for the link!

  • @rishabh7g
    @rishabh7g 4 หลายเดือนก่อน

    I felt like I was collobarting with you while you were explaining in the video. I am sure there are people like me who understands well with this approach. Keep it up, mate.

  • @SahraClayton
    @SahraClayton 2 ปีที่แล้ว +3

    Hi Cody, on line 27 in the wrapPromise file, how does handler[status]() work. I haven't seen syntax like this since I have been learning, I have seen something similar with square brackets but not with parenthisis afterwards.

    • @jersoncarin1952
      @jersoncarin1952 2 ปีที่แล้ว +4

      it just calling the callback function by key

    • @atkevindsouza
      @atkevindsouza ปีที่แล้ว

      handler is of type Object void>
      So handler[status] gives the value at key `status` which is a function, which is then invoked using the ().

  • @codinginflow
    @codinginflow ปีที่แล้ว +1

    Thank you, that was super interesting. It's probably good that NextJS hides a lot of this complexity.

  • @bernardoolisan1010
    @bernardoolisan1010 4 หลายเดือนก่อน

    wouldn’t it be better to use async/await in the wrapPromise?

  • @nguyentrunghieu6200
    @nguyentrunghieu6200 2 ปีที่แล้ว

    Hello, I have a question. How does React know when to render the suspended component? Does React verify if the component belongs in the viewport?

  • @BobbyBundlez
    @BobbyBundlez 2 ปีที่แล้ว

    imho that whole promisewrapper thing is a bunch of extra abstraction and convolution to this lol. glad you agreed though haha

  • @dcknature
    @dcknature 2 ปีที่แล้ว

    Learned about react Suspense thanks to your channel ☺️👍!

  • @kerovinvillegas6402
    @kerovinvillegas6402 ปีที่แล้ว +2

    Thanks for this. My job title is "Senior" react dev but I'm still using console log for debugging/testing things out. Just found it funny to know there are devs out there like me. I know there are better ways but yeah I like it haha

    • @apharos
      @apharos ปีที่แล้ว +2

      there are 2 types of devs:
      Those that use console.log / print to debug and
      liars

  • @iganic7574
    @iganic7574 7 หลายเดือนก่อน

    Is react suspense is for server side rendering stuff ?

    • @WebDevCody
      @WebDevCody  7 หลายเดือนก่อน +1

      Yes

  • @absurd0000
    @absurd0000 ปีที่แล้ว

    Great video! Thanks

  • @pedrotorchio
    @pedrotorchio 11 หลายเดือนก่อน

    nice. Thanks for this.

  • @SeibertSwirl
    @SeibertSwirl 2 ปีที่แล้ว

    Good job babe!!!

  • @yabuking84
    @yabuking84 7 หลายเดือนก่อน

    Why cant the react team create the Suspense feature that components can just return a promise? This is too convoluted.