Next.js 13 Changed Data Fetching and Rendering... But Is It Good?

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

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

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

    Hands down the most comprehensive next js video on this topic. Keep up the amazing content!

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

      Wow, thanks! I really appreciate that :)

  • @easyitlearn-g1k
    @easyitlearn-g1k 7 месяцев назад

    that's amazing video on next js Data Fetching and comparison between next 12 vs 13. well done. Thank you for sharing your knowledge on such a this simple and easy way

  • @ahmedkhalid-ld1ex
    @ahmedkhalid-ld1ex Год назад

    This video should be popping off.. best next13 features explanation out there .. great job, buddy.

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

    Best explanation of v13 changes to rendering / data fetching I've found. Please more NextJs videos :-)

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

      Thanks, will do! More will come :)

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

    im still learning nextjs
    your video looks interesting
    saved to "watch later" thanks

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

    Very helpful explanation !!
    Is there a way to mimic getInitialProps in next 13?

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

    The best NextJs video I have seen. Thank you

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

      Thank you, I'd appreciate that a lot :)

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

    Using Vue currently, I'm very sure your videos will help me catch up with NextJS next time I return to using it, thanks!

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

      Sounds great! Glad it was helpful :)

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

    Fantastic video explaining these confusing differences! Question regarding ISG in Next.js 13 with static paths: so you can add the revalidate parameter to the fetch call in getPost, and this makes sure that any update to a particular post gets rebuilt, but what about the fetch call inside the generateStaticParams? Would that also need a revalidate param in order to make sure that after adding a new post to the list, its id gets added to the static list of paths?

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

      When you update a post from your database or through a CMS, generateStaticParams is not called again. By default, dynamic segments not included in generateStaticParams are generated on demand. This means that the data is also cached. You can disable this by exporting "export const dynamicParams = false" in your page.js, layout.js or route.js file. It's set to true by default. Exporting it to false will return 404 for posts that were not generated statically at build time. So it's best to leave it set to true and not export it. This will eliminate the need to rebuild your site, which is the only way to call generateStaticParams again.
      To show the updated version of your post, you can use time or on-demand revalidation. Time revalidation is as simple as adding the revalidate option to your fetch function like this "fetch('...', { next: { revalidate: 3600 } })". The value is in milliseconds. On-demand revalidation can be done by path (revalidatePath) or by cache tag (revalidateTag) inside a route handler or server action. Here's it's best to check the docs for implementation, but one example would be to use webhooks if you use a CMS and call the route handler to revalidate the path. generateStaticParams works like getStaticPaths, so you could look for how revalidation was implemented with getStaticPaths to get an idea of a good workflow. Hope this helps :)

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

      @@CodeSnaps Thanks for the comprehensive response! In the second paragraph, you are discussing the revalidation parameter for the getPost function, but what about the fetch call from the generateStaticParams? Does that support the revalidate param as well with the same effect? (i.e., rebuild the static paths every N seconds)

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

    Thank u so much, knowledge base is useful

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

    this is awesome!. I want to ask, is generateStaticParams function revalidate on new data? or we should add params next{revalidate} on function enerateStaticParams ?

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

      Thank you very much! So generateStaticParams doesn't revalidate for new data. However, you can add 'next: { revalidate: X }' to the fetch function where, for example, you fetch a single post, not to the fetch function inside generateStaticParams. So add 'fetch(URL, { next: { revalidate: 3600 } })' to getPost() and not inside generateStaticParams(). This only works with the native fetch function. If you are using libraries like axios, then add 'export const revalidate = X' somewhere on the page where you call generateStaticParams. Hope this helps!

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

      @@CodeSnaps Oh I see,thank You so much. I just know the export const revalidate = X for another fecthing data like axios.Its very clear with this explanation.Thanks brother👍

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

    Hey man, that was a great and very informative explanation, but I wondered can we cache the request time data like can we cache the data sent from the server so may be we can have faster performance and also just changing the cache option we are changing whether the site is rendered on build time (just once) or page is served from the server or request time(on every page request), right?

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

      I hope I understood your questions correctly. The data that is fetched from the server is automatically cached, even with revalidation, because it shows the cached data first, and after revalidation it sets a new cache. The data is cached once at build time, but if you add revalidation with something like "fetch('...', { next: { revalidate: 3600 } })", then the data is cached again after revalidation. This means that we always have better performance because the data is fetched from the server and cached. If you use something like "fetch('...', { cache: 'no-store' })", then the data is not cached, but fetched on every single request. Just using fetch alone with no other options (default) will automatically cache it once per build time. It won't fetch it again, you need to revalidate for that. Hope that helps!

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

    Well done, very clear explanation

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

      Thanks, glad you liked it :)

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

    Great videos, thank you! Can you make video how to do a list products page which has "Load more" button, I don't know what is the best way to do that with Nextjs 13, I don't really want to use client component?

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

      Sure, but if you want to fetch more todos in a todo list, you'll need to use a client component. However, the first, let's say 20 todos can be fetched via the server using server components. Then when the user clicks "Load more", you use a client component to show more todos. This way you can use both server components and client components at the same time.

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

    This was awesome!!

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

      Thank you :)

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

      No seriously, i'm working on a project right now and as a "beginner" this was probably one of the best videos i've seen in my research. I actually saved it. I would love to have you check out my project!@@CodeSnaps

  • @paulmothapo
    @paulmothapo 11 месяцев назад

    Thank you❤️🔥

  • @abhishekchandel4244
    @abhishekchandel4244 6 месяцев назад

    appreciate the quality of the content

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

    Very informative

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

      Thanks! Glad you liked it :)

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

    This is great

  • @chi-mf1cx
    @chi-mf1cx Год назад

    Amazing content brooo...

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

    Can you do a video on React Query in Next 13+ thank you!

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

      Sure thing! It's a good idea, thanks :)

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

      If I'm not mistaken we have no possibility to use react query inside the server component we can use it if we add "use client'' on the top of the page component. Will be great to have the possibility to use react query inside server page component(.
      Because it's very sad to use native fetch we will have no isLoading, isError and etc...