Next.js 13 - Data Fetching & Suspense Boundaries

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024
  • Next.js 13 data fetching is the topic of this video. We will learn how to handle data fetching in the app folder and how to use React suspense boundaries to enable granular loading UI for data fetching. We will build a simple dashboard application that fetches data from two endpoints.
    Next.js 13 - How to use App folder & Layouts: • Next.js 13 - How to us...
    Learn Programming (Skillshare FREE trial): skl.sh/3cYxUP5
    My courses:
    React basics: skl.sh/2XAKn7u
    HTML & CSS for beginners: skl.sh/34wvGUH
    Draft.js basics: skl.sh/3cJ5Hw4
    💻 MY GEAR
    MY CODIGN LAPTOP: amzn.to/3MI90ci
    MY MOUSE: amzn.to/3mr3no9
    MY KEYBOARD: amzn.to/3GIoMjh
    MY MICROPHONE: amzn.to/3KCDPfv
    MICROPHONE BOOSTER: amzn.to/43trLWB
    MY MICROPHONE ARM: amzn.to/3oaf5DW
    MY CAMERA: amzn.to/3UxyvyJ
    MY STREAMING LIGHT: amzn.to/3KE0PuE
    Connect with me:
    Website: tuomokankaanpa...
    My newsletter: tuomokankaanpa...
    Twitter: / tumee
    Skillshare: www.skillshare...
    #nextjs #suspense #react

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

  • @frontendonly
    @frontendonly Год назад +1

    Error: This Suspense boundary received an update before it finished hydrating. This caused the boundary to switch to client rendering. The usual way to fix this is to wrap the original update in startTransition.
    How to solve this error?

  • @amalio1
    @amalio1 Год назад +3

    Great job,the first to talk about this new NextJs 13.
    It will be great if you could make a video explaining the error and template to, but amazing job ,new subscriber here!

  • @temez1
    @temez1 Год назад +2

    Good demo. A bit slow to my taste, 1.75 worked. Or maybe more editing and skipping things eg. Fireship.
    I'm not sure if the separation of loading states is a good design. The loading waterfall is a bit ugly imo.
    Good job anyways & it's nice to see Finn dev channel.

  • @RusselFury
    @RusselFury Год назад +2

    learned something new again, thanks! :)
    btw, have you tried to show images with fetching? I'm trying, but can't get images loaded (pending status), are there any tricks with it in new app directory?

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  Год назад +1

      Great to hear! I actually haven't tried showing images while fetching, that is interesting that they aren't working. Gotta test that out!

  • @XiovV
    @XiovV 10 месяцев назад

    Doesn't this break the single responsibility principle? In order for Suspense work you have to do the data fetching inside the component you are wrapping in Suspense, but that breaks the single responsibility principle, as the component is now responsible for data fetching AND rendering. Let's say I want to fetch an array of companies from the parent component, then pass them to the Companies component as a prop, is there a way that can be done? I tried it but it just hangs the entire page until the data fetches, probably because it's fetching inside the parent component.

  • @avertry9529
    @avertry9529 Год назад +1

    How does that work with reusable components, to save duplication to multiple folders?

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

      I wouldn't save it multiple times, I would just import it from the path it is in :)

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

    im trying to do this in typescript but getting
    return type 'Promise' is not a valid JSX element.
    Type 'Promise' is missing the following properties from type 'ReactElement': type, props, keyts(2786)

  • @jatinduggal1975
    @jatinduggal1975 7 месяцев назад

    how to use suspense with useEffect as we do not only need to bring data, we need to hit other apis too, i am struggling to use suspense with useEffect

  • @eliuddyn
    @eliuddyn Год назад +2

    Amazing 🔥🔥

  • @biLLie_wiLLie
    @biLLie_wiLLie Год назад +1

    Wow, first Finnish developer)

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

    i got this Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.
    still trying to figure it out.

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

      Did u figure it out? From the looks of it might be that you are rendering the items before the promise is resolved

  • @pedrol6193
    @pedrol6193 10 месяцев назад

    Dude sounds like Clank

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

    Sup, amazing video! But I have a problem. VS Code showing a message:
    '' 'Header' cannot be used as a JSX component. Its return type 'Promise' is not a valid JSX element. ". And it works fine in the browser, has this ever happened to you?

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

      Thanks man! It’s hard to say without seeing the code but check out this thread hopefully it is helpful stackoverflow.com/questions/62702485/component-cannot-be-used-as-a-jsx-component-its-return-type-element-is-not

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

    can you still do this with local json data?

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

    Hello, thanks for the video, I have a question, at what point is it useful to use suspense rather than letting the component loading please? Is it specific to data? And last question, I'm building a site with strapi, can I put the fetch calls in the /api folder on the server or should I create a lib folder in the app and put all my fetch requests (I can also put it on the page like you did but it's to keep everything separate) thanks for your answer

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

    too small look dude to watch on a mobile

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  Год назад +1

      Sorry to hear that, it’s prolly indeed better to watch on desktop!

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

    thanks... what about On-Demand Revalidation data fetching with next js 13 ??

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

      Good question! I’m planning to make a video about this!

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

    No more need to use getServersideProps?

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

    Thnxs man. I needed a refresh on how that worked now. My lint was going frakking mad

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

    github Repo ????

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

      Here: github.com/tumetus/next-js-13-data-fetching-test

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

    Explained it very simply..thank you

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

    I had to give you a subscription cuz no one else is churning out content on these experimental features like you.

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

    This is really cool! I do have one question though. Wouldn't having those loading components produce a lot of Cumulative Layout Shift issues? Google could really ding you

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

      Good question, I would say that it also depends on what kind of stuff you display for loading states

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

    @TuomoKankaanpaa is there any method to refetch the data after post reqest in client component? Cuz after router.replace() to server component where data is fetched i need to refresh to see new data.

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

      There is a way to do refetching that is described here beta.nextjs.org/docs/data-fetching/mutating

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  Год назад +1

      There is a way to do refetching that is described here beta.nextjs.org/docs/data-fetching/mutating

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

    Great video! Could you please add the code in Github? Where are the APIs stored, in which format? I'm stucked....thank you

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

      Here is the code for the API server github.com/tumetus/json-api hope it helps!

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

      @@TuomoKankaanpaa thanks! In your video we don't see where the folder api is saved. Is it in the app folder? is the Github code done with Next.js 13? In your video you have "users" defined as an object in Github you have a list defined as const users = [{....}].

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

      @@patite3103 the github code is using next.js 13 also. You need to clone the repo and then run the server locally with e.g. "yarn dev" and you can then access it in localhost:3000 or 3001

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

    Love your accent and teaching style bro

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

    user component is server side render or static page at production

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

    Great job Tuomo, your videos are amazing. want more videos for nextjs 13

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

      Thank you Ashik! Anything specific about nextjs 13 you would like to see a video about?

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

    You provided a great explanation, thanks

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

    How to use relative fetch paths, so instead of fetch("localhost:3000/api/*" to just use fetch("/api/whatever");

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

      I explain the use of relative paths later in the video so check out the end half of the video!

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

      @@TuomoKankaanpaa thank you for the great content!
      Can't find this point, can you please add timestamp for it?
      I am struggling with performing fetch request to my secured api (using next-auth) from a server component , when using the full path the session is null

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

      @@bennagar Hey Ben! It indeed isn't in this video, my bad! You can find how I handle it with rewrites in here: ruclips.net/video/Y1FwWlBFUi8/видео.html

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

    Please explain “use client” coz I couldn’t use usestate normally as I would use. Thanks in advance

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  Год назад +1

      Planning on making video about server and client components. ”use client” will be used in that vid!

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

      @@TuomoKankaanpaa thanks 🙏

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  Год назад +1

      @@hudheyfa the video on server and client components went just live!

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

    Yours videos are great! Thank you for yours work.

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

    Awesome explanation! Thanks a ton

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

    Good job Tuomo! 👏👏👏💯

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

    What theme are you using? Nice one 🙂

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

    Suspense is cool 🔥🔥

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  Год назад +1

      Indeed!

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

      The way you explain whole thing is also cool 🔥 😎

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

      @@TuomoKankaanpaa can you make video about how to use search with api data in Nextjs 13 in optimal way ?

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

      @@utkarshseth3082 Sorry I'm not 100% sure what you mean, can you elaborate a bit more? :)

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

      @@TuomoKankaanpaa like in normal Nextjs projects if we want fetch some data with search condion we use useffect and Usestate with input onChage method ,
      My question- is there any optimal way for this that you for production level app ? I don't have much experience with recat that's why or my be any simpler way in nextjs 13 that you might have any idea about this ... 😅