First Look at React Suspense for Data Fetching

Поделиться
HTML-код
  • Опубликовано: 25 авг 2024

Комментарии • 125

  • @DanBorgia
    @DanBorgia 4 года назад +15

    Thanks for the Ctrl+Space shortcut for auto-import. Gonna use that one a lot!

  • @bensmith807
    @bensmith807 4 года назад +98

    I’m a simple guy. I see a new video about react from Ben Awad, I watch it

  • @WrongAkram
    @WrongAkram 4 года назад +9

    Thanks for being consistent 🙏🏽

  • @georgebelanger
    @georgebelanger 4 года назад +13

    Hey man really like you calling out what hot keys you're using. It seems a little boiler platey to me but definitely looking forward to more videos on this topic!

  • @zeno_aratus
    @zeno_aratus 3 года назад +1

    great liked the tip for slowing down network operations! Man thats a great tip

  • @8Trails50
    @8Trails50 4 года назад +3

    Ben awad is the only dev channel i watch nowadays lol

  • @planetmall2
    @planetmall2 4 года назад +3

    As always great job! I’ve learned a lot from you.

  • @Xyfi
    @Xyfi 2 года назад

    Love how I watched this video 2 years ago and now again since react 18 released 😂

  • @filcondrat
    @filcondrat 4 года назад +2

    looking forward for React Concurrent Mode series

  • @jcantado3774
    @jcantado3774 4 года назад

    Thanks for another great feature introduction

  • @thiagoleite3255
    @thiagoleite3255 Год назад

    Thanks for sharing

  • @smakosh
    @smakosh 4 года назад +9

    "Let's create a person" :D

  • @AndrewRymaruk
    @AndrewRymaruk 4 года назад +1

    thanks for the explanation!

  • @gevikb
    @gevikb 4 года назад +2

    Very nice introduction. BTW: The name of that person translates to: en.wikipedia.org/wiki/Cyrus_the_Great

  • @amjedbouhouch7993
    @amjedbouhouch7993 4 года назад

    Thank you for the wrapPromise

  • @smakosh
    @smakosh 4 года назад +1

    Another example using star wars API: codesandbox.io/s/fetching-data-and-rendering-with-suspense-0g83m

  • @mahyarekramian9040
    @mahyarekramian9040 3 года назад

    awli bud dadash

  • @mubasharhassan1979
    @mubasharhassan1979 3 года назад +1

    I Got This Error
    TypeError: react_dom__WEBPACK_IMPORTED_MODULE_1___default.a.createRoot is not a function

  • @jamesyu2919
    @jamesyu2919 4 года назад

    Thank you, this is very helpful to me.

  • @colorofadog
    @colorofadog 4 года назад

    Tnx, very useful!!

  • @trymoto
    @trymoto 4 года назад

    Thanks, this is inspiring

  • @aashishtiwari297
    @aashishtiwari297 4 года назад

    Hi Ben , can you explain the interruptible rendering in Concurrent mode by an example ?

  • @smashed5826
    @smashed5826 4 года назад

    Nice video, just one part I don't understand why not utilize the "async" syntax but dive into the promise status checking in wrapper? Btw, I like the sound of your machanical keyboard :)

    • @bawad
      @bawad  4 года назад

      you could do async/await instead of .then just preference

  • @bennycode
    @bennycode 4 года назад

    Great video! With React Suspense can you also make the loading of one component wait for another one to finish first? I am thinking of cases where one components needs the other. Is there something similar like "dependencies" in "useEffect"?

    • @bawad
      @bawad  4 года назад +1

      With SuspenseList you can declare an order they display in ruclips.net/video/KO8rPRyCZd4/видео.html

  • @aqua123670
    @aqua123670 4 года назад

    Hi Ben, nice vid. One questions. so how React knows when it needs to render the fallback or the content is from the Promise that we throw ?

    • @bawad
      @bawad  4 года назад +2

      if you throw a promise, React will show the fallback until the promise is resolved

  • @YossiDagan
    @YossiDagan 4 года назад

    super nice

  • @zkabadu
    @zkabadu 4 года назад

    I am working with React Suspense for Data Fetching a while now, but what I didn't get so far is, if it is only for reading of data or also for updating/creating/deleting of it. What I mean is, is this some kind of command query separation and can it replace redux at all (for simple things). What do you think?

    • @bawad
      @bawad  4 года назад

      I think it's more for reading data, but we'll see when data fetching libraries start to integrate suspense in

  • @rotimibest8530
    @rotimibest8530 4 года назад

    Ben what do you use that makes your terminal have auto complete and coloring?

    • @bawad
      @bawad  4 года назад +2

      benawad.com/theme
      benawad.com/vscode

  • @neilbertmillar9960
    @neilbertmillar9960 4 года назад

    can you do tutorial for table scrolling with suspense?

  • @elie4676
    @elie4676 4 года назад

    So just for clarification : all of this is an alternative to checking if the data exists in the state? I do know that axios does fetching states as well, no?

    • @bawad
      @bawad  4 года назад +1

      it's a different way to control loading states. It's goal is to simplify complex loading scenarios

    • @elie4676
      @elie4676 4 года назад

      @@bawad Thanks!

  • @sorinlates
    @sorinlates 4 года назад +2

    noob question: does Suspense work in react-native?

    • @bawad
      @bawad  4 года назад +1

      I'm not sure if it works right now, but it will

    • @permanar_
      @permanar_ 4 года назад

      Might be a bit OOT but try Flutter. It has something like this but called FutureBuilder Widget!

    • @Endomorphism
      @Endomorphism 4 года назад

      as long as its JS it work

  • @gofudgeyourselves9024
    @gofudgeyourselves9024 4 года назад +1

    Can we do post and put with suspense??

    • @bawad
      @bawad  4 года назад +1

      I don't see why not, I'll show an example in the next video

  • @gatodetaco
    @gatodetaco 4 года назад

    I have a question, is suspense some sort of try/catch React component? like, when any of its children throws an error, it renders the fallback?

    • @bawad
      @bawad  4 года назад

      yeah kinda

    • @thebasedone2182
      @thebasedone2182 4 года назад

      I think it works on top of the ErrorBoundary component and does some polling to retry re-rendering the component

  • @peterbolton7564
    @peterbolton7564 4 года назад

    Hi Ben is Suspense preferable to async/await why would you choose one over the other ? BTW the videos are really helpful !

    • @bawad
      @bawad  4 года назад

      Suspense works with promises you can use .then or async/await syntax just comes down to preference

    • @peterbolton7564
      @peterbolton7564 4 года назад

      @@bawad I guess what I'm asking is you could achieve the same as Suspense (with fallback) using async /await with useState (loading..) either side of the the await so why use Suspense

    • @31redorange08
      @31redorange08 4 года назад

      It seems like a dirty hack to me, throwing something to make it work.

    • @bawad
      @bawad  4 года назад

      for basic examples it's easy to emulate with useState, but Suspense will be helpful for more complex scenarios

  • @shirshak6738
    @shirshak6738 4 года назад +1

    i think i saw suspense last year by dan at some conference lol

    • @piyushgupta809
      @piyushgupta809 4 года назад

      Well its released just now !

    • @baptiste6436
      @baptiste6436 4 года назад

      @@piyushgupta809 experimentally or official?

  • @t1x1j
    @t1x1j 4 года назад

    Cool, looks good. Hopefully will come to prod soon. :) BTW... Why do people still use yarn these days? I have so much problems with yarn fetching packages... Most of the time it's sth like "unexpected end of file". I'm switching back to npm because of this.

    • @bawad
      @bawad  4 года назад

      interesting, I've had a better experience with yarn

  • @huehuehuehu9429
    @huehuehuehu9429 4 года назад

    How'd you make your cursor change from line to block on move?

    • @bawad
      @bawad  4 года назад +1

      shift-v in vim

  • @Gbd279
    @Gbd279 4 года назад

    Can I use suspense within the Num and Person Components?

    • @bawad
      @bawad  4 года назад

      You have to make sure wherever you call the function to get the data that you wrap that component in Suspense

  • @TheGodLovely
    @TheGodLovely 4 года назад

    Hello sir... how your IDE show the curly brackets connected yellow line.

    • @bawad
      @bawad  4 года назад

      benawad.com/theme

    • @karoI508
      @karoI508 4 года назад

      you could try installing bracket pair colorizer

  • @heycezer
    @heycezer 4 года назад

    How can this be applicable to using graphql endpoints and Apollo package?

    • @bawad
      @bawad  4 года назад +2

      When this is released Apollo will probably build an api around it, so we can start using it to handle loading states there too

  • @shirshak6738
    @shirshak6738 4 года назад +1

    that gyp error on macos freaks me out.

    • @bawad
      @bawad  4 года назад

      same

  • @z-aru
    @z-aru 4 года назад

    9:30 "Unexpected name of a person"

    • @bawad
      @bawad  4 года назад +2

      after read()
      console.log the person to see what it looks like

  • @CoryTheSimmons
    @CoryTheSimmons 4 года назад +6

    RUclips success... Haircut... Lost the glasses... If you're working out as well then you're leaving us and joining the Chad Army. 😨

    • @filcondrat
      @filcondrat 4 года назад

      accidentally googled the Chad Army
      guess this is not what you meant 😆

    • @bawad
      @bawad  4 года назад +1

      you should come join the Chad Army, it's pretty nice on this side

  • @Mr-Multiplayer
    @Mr-Multiplayer 4 года назад

    Amazing video and well explained
    +1 subscribe 😍

    • @bawad
      @bawad  4 года назад

      welcome :)

  • @mystery7546
    @mystery7546 4 года назад

    I've already used this feature 4 months back in production.

  • @broodfusion
    @broodfusion 4 года назад

    for some reason i'm getting person.name.first is undefined, network request is good
    same exact code

    • @bawad
      @bawad  4 года назад

      if I had to guess github.com/benawad/react-suspense-example/blob/1_suspense_intro/src/PersonApi.js#L4

    • @broodfusion
      @broodfusion 4 года назад

      as of 10/29, ReactDOM.create_root is ReactDOM.unstable_createRoot, and it looks like whatever change was made to the experimental React makes Ben's code not 100% compatible. To get this to work as in the video, I had to clone Ben's repo.

  • @weltmeister
    @weltmeister 4 года назад

    can you do a video on how to secure your graphql API? like creating role based requests and API keys and tokens... etc

    • @bawad
      @bawad  4 года назад

      if you want to setup API keys, are you wanting to do a public graphql api?

    • @weltmeister
      @weltmeister 4 года назад

      @@bawad it's more like a private one, I just want an example as I don't know where to start with this, and thank you so much for the reply it means a lot.

    • @bawad
      @bawad  4 года назад

      here's an auth example ruclips.net/video/qCnQgZzoIMM/видео.html

  • @none0n
    @none0n 2 года назад

    That is a lot of code for loading feedback

  • @gofudgeyourselves9024
    @gofudgeyourselves9024 4 года назад +1

    I am a beginner in react can you please let me know How is this better than axios or fetch?

    • @RhinoAndre
      @RhinoAndre 4 года назад

      Actually, this is not meant to replace axios or fetch. It's a way to "automatically" render a loading when your are fetching the required data.

  • @girlswithgames
    @girlswithgames 2 года назад

    10:48

  • @manfredadams3252
    @manfredadams3252 4 года назад +2

    So... much... boilerplate...

  • @publicuser993
    @publicuser993 4 года назад

    That's was Persian name

  • @Patrick1985McMahon
    @Patrick1985McMahon 4 года назад +3

    I don't see the benefit. I can already do this in a clean organized way using redux.

    • @frontendtony
      @frontendtony 4 года назад

      Same here (not with redux though). I'll wait for the official release to see the actual benefits, if any

    • @thebasedone2182
      @thebasedone2182 4 года назад +3

      read the documentation about the React Concurrent Mode as well as data waterfall

    • @z-a3594
      @z-a3594 4 года назад

      Then there is a benefit since you had to do something like this in the past, new projects could use this new way once it is production ready. Also, with the context api, this and others FB may be trying to provide the features without having to use redux. Glhf

    • @Patrick1985McMahon
      @Patrick1985McMahon 4 года назад

      @@z-a3594 and that has already been resolved with basic components and redux and is a lot easier. Redux also works great for large applications so why do I need this over just handling it in my state change with my reducers

    • @jhoanborges6574
      @jhoanborges6574 4 года назад

      It's an effort to stop using redux...

  • @celidee
    @celidee 4 года назад +2

    Suspense is sexy AF

  • @nubl3718
    @nubl3718 4 года назад

    is apollo going to support suspense?

    • @bawad
      @bawad  4 года назад

      probably

  • @noelsoong777
    @noelsoong777 4 года назад

    Wwawat so no need for thunk?

    • @bawad
      @bawad  4 года назад

      nope

  • @nicolastoulemont3609
    @nicolastoulemont3609 4 года назад +2

    Ben, would you consider adding a mid-tier between 10$ to 15$ patreon membership level ? 5$ is really not enough given the very strong quality of your content but not everyone can give 100$ :)

    • @bawad
      @bawad  4 года назад

      I would, but couldn't think of a good reward. Let me know if you have any ideas.
      Also you can do a custom pledge with any amount

    • @nicolastoulemont3609
      @nicolastoulemont3609 4 года назад

      @@bawad If you have the time, I think high level view of projects can be of interest such as from the start of a project to its full automated deployment workflow in production but that maybe is more of a Udemy (in 5 to 15 hours of content) type of product than a RUclips kind of one. But I know that it has been a real success for other youtubers such as Traversy media full stack MERN Udemy course.
      Maybe having a restricted access based on membership for a few weeks / months could be a good reward.
      Anyway, thank you for your content, keep up the good work :)

    • @bawad
      @bawad  4 года назад +1

      I like making that type of content (and probably will make another fullstack project soon), but it takes SO long to finish something

    • @FirroLP
      @FirroLP 4 года назад +1

      @@bawad There doesn't need to be a reward at Patreon, the videos you already produce are why we would consider donating.

  • @nac9880
    @nac9880 4 года назад +1

    2x speed because your time matter 😉

  • @thewirv
    @thewirv 3 года назад

    this is so cringe without TypeScript

  • @dallas-cole
    @dallas-cole 4 года назад

    I used to be an x parameter guy.

  • @michaelcain4063
    @michaelcain4063 4 года назад

    yout type so fast lol

    • @bawad
      @bawad  4 года назад

      yes and I use vim so it may look like I'm typing fast at times when it's really a shortcut

  • @SalmanAbbas007
    @SalmanAbbas007 4 года назад

    I am saddened by this crazy abuse of the throw statement. It's pointless complexity IMO. I just use Bluebird promises, they support inspection so I can just render a loading message by checking promise.isPending(). As a bonus, it supports promise cancellation. So we can cancel unneeded fetchs on unmount. 👌

  • @ProtectedClassTest
    @ProtectedClassTest 4 года назад

    Bro i dont know but it so weird with you looking up, maybe put the camera in your eye level

  • @zlackbiro
    @zlackbiro 4 года назад

    To avoid Suspense, create one state to show loading, when the data arives, inside then, swap loading state with data state. One if, two states, 3 lines of code. 😳 People nowadays will start using libraries even for input fields. Lazy people will destroy programming industry...