How to Correctly Use Fetch In Next.js

Sdílet
Vložit
  • čas přidán 27. 08. 2024
  • Get exclusive Next.js content: bit.ly/free-we...
    ⚡️My newsletter: tuomokankaanpa...
    X: / tumee
    #nextjs #reactjs #nextjstutorial
  • Věda a technologie

Komentáře • 13

  • @Kassq
    @Kassq Před 4 měsíci

    Good, until you require certain page parameters that are only accessible at the page level. I've noticed a significant amount of prop drilling with i18n, where language parameters are passed as props, which are necessary for certain queries. For instance, if I have page.tsx => server1.tsx => server2.tsx, I don't believe there's a particularly efficient way to pass the language parameter from page.tsx to server2.tsx. 🤔

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  Před 4 měsíci

      Good point, that is indeed a challenging situation! I'm not sure either if there is a efficient way for passing the language parameter down multiple layers. Off the top of my head maybe one way could be to circumvent the prop drilling by setting the language param to cookies and getting it inside the components with cookies from next/headers nextjs.org/docs/app/api-reference/functions/cookies

    • @Kassq
      @Kassq Před 4 měsíci

      @@TuomoKankaanpaa works but afaik that also makes component dynamic meaning on demand rendering. Not reallt ideal when you always have some known subset of languages.

  • @trusht
    @trusht Před 4 měsíci

    Thank you for the great tips🙏

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  Před 4 měsíci

      You are welcome, glad to hear you liked it! I share more tips also on my newsletter bit.ly/free-webdev-advice check it out if at all interested!

  • @RedSkyWan
    @RedSkyWan Před 4 měsíci

    i'm confused. why you make your api by express??? Next.js can do it without any library

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  Před 4 měsíci

      I just wanted a simple, lightweight, quick api for the demonstration purposes for this example and decided to go with that :) but you are right, could have just easily do it with Next.js!

  • @azizouichni
    @azizouichni Před 4 měsíci

    Yes, the recommaded way is to fetch data inside every component who needs that data, because if we are using the extend "fetch" the data gonna be cached automatically.
    Also we can use "'cache" from React if we don't use "fetch"'.

  • @behroozshafei3511
    @behroozshafei3511 Před 3 měsíci

    fonts are too small

  • @vincesalazar5719
    @vincesalazar5719 Před 4 měsíci

    Promo'SM 😑