Templates vs Layouts in NextJs 13

Поділитися
Вставка
  • Опубліковано 25 сер 2024

КОМЕНТАРІ • 91

  • @kyle-andrewgovinder9902
    @kyle-andrewgovinder9902 10 місяців тому +2

    I absolutely love your content
    Nextjs is easily one of the most in demand tech currently and you're providing one of most clear and concise resources for learning it all the way from the basics to the more advanced topics
    I hope your channel continues to grow, you deserve every success

    • @hamedbahram
      @hamedbahram  10 місяців тому

      Thanks Kyle! I appreciate your comment, and I'm glad you're finding the videos helpful.

  • @fluFFPfizschi
    @fluFFPfizschi 7 днів тому +1

    Finally I understood that, thank you! 🙂

  • @andrew_schaeffer
    @andrew_schaeffer 9 місяців тому +1

    Wonderful lesson thank you. I'm reading throught the NextJS docs now and am so glad you cleared up the difference between layouts and templates.

    • @hamedbahram
      @hamedbahram  9 місяців тому

      My pleasure! Glad it was helpful.

  • @rohitghodeswar11
    @rohitghodeswar11 10 місяців тому +3

    Again top notch content on NextJS
    Thank you, keep it up 👍🏻

  • @uzairahmed2975
    @uzairahmed2975 6 місяців тому +1

    Thank you Hamed, This video makes a lot of sense to understand between layout and template.

  • @Gangbuster74
    @Gangbuster74 10 місяців тому +1

    congratulation for reaching 10k subs well deserving, your content is really great explaing all the bits and pieces of front end development

    • @hamedbahram
      @hamedbahram  10 місяців тому

      Thanks! I appreciate it.

  • @samuelizevbizua
    @samuelizevbizua 7 місяців тому +1

    Thank you Hamed, It's been nothing but Imppactful and Growth since i subscribed to your channel

    • @hamedbahram
      @hamedbahram  7 місяців тому

      My pleasure! Glad to hear that.

  • @onyejemeemmanuel94
    @onyejemeemmanuel94 29 днів тому +1

    Nice content. Thanks for explaining concept well

  • @jazsouf
    @jazsouf 10 місяців тому +1

    Nice explanation, so if you have similar code in two different pages that share the same parent folder, you can extract that code into a common template and put it in the parent folder.
    It can also provide a client wrapping mechanism to your nested server pages!

    • @hamedbahram
      @hamedbahram  10 місяців тому +1

      Yes, exactly! You can accomplish that with both `layout` and `template`. The difference is `layout` doesn't re-render on page navigations whereas `template` does.

  • @devmab
    @devmab 10 місяців тому +1

    Thank you so much for your support and teaching, I'm really understanding your explanations.

    • @hamedbahram
      @hamedbahram  10 місяців тому

      You are very welcome. Glad to hear that!

  • @tysondolan1533
    @tysondolan1533 24 дні тому

    You are a great instructor!

  • @nikhilpsathyanathan
    @nikhilpsathyanathan 7 місяців тому +1

    I thought it just like layout but this video is awesome. Got to know more about template' functionality

  • @albert21994
    @albert21994 7 місяців тому +1

    Clear and understandable examples. Thank you!

  • @tatsumii1420
    @tatsumii1420 8 місяців тому +1

    we would love a framer motion video with nextjs

    • @hamedbahram
      @hamedbahram  8 місяців тому

      Absolutely! That has been overdue. Will work on it.

  • @yuensc196
    @yuensc196 8 днів тому +1

    clear explanation

  • @hasancheraghi2800
    @hasancheraghi2800 10 місяців тому +1

    Thank you Hamed. I appreciate your fantastic tutorial

    • @hamedbahram
      @hamedbahram  10 місяців тому +1

      Anytime Hasan! I'm glad it was helpful.

  • @anversadutt
    @anversadutt 10 місяців тому +1

    congrats bro for the 10K, keep rocking :)

  • @arihantjain3274
    @arihantjain3274 9 місяців тому +1

    This is Gold

  • @user-hc2nc1el5k
    @user-hc2nc1el5k 10 місяців тому +1

    Best regards from Egypt

    • @hamedbahram
      @hamedbahram  10 місяців тому +1

      Welcome to the channel!

  • @afshinkaramifar4429
    @afshinkaramifar4429 9 місяців тому

    Such a great explanation, Well done Hamed👏

  • @CHIRANJIBNANDY1
    @CHIRANJIBNANDY1 4 місяці тому

    beautifully explained

  • @toone4068
    @toone4068 9 місяців тому +1

    thank you

  • @shahryartavakkoli
    @shahryartavakkoli 10 місяців тому +1

    Thanks

  • @maskman4821
    @maskman4821 10 місяців тому +1

    Great tutorial ❤

    • @hamedbahram
      @hamedbahram  10 місяців тому

      Thanks! Glad you found it helpful.

  • @2gbeh
    @2gbeh 10 місяців тому +1

    🇳🇬 Great job

  • @MohammedIbrahim-fl2sx
    @MohammedIbrahim-fl2sx 5 місяців тому +1

    i have a login page (Auth pages) how can i remove the components in RootLayout in those pages

    • @hamedbahram
      @hamedbahram  5 місяців тому

      You can use route groups to create to different layout. Watch this → ua-cam.com/video/Go4rL15gYTs/v-deo.html

  • @samislam2746
    @samislam2746 9 місяців тому +1

    So what's the purpose of having a layout with a "use client"?
    Anytime someone wants to use "use client' he can right away use a template instead.
    And also, why would someone use template without 'use client"? Any case will always use "use client".?
    I'm a bit confused.

    • @hamedbahram
      @hamedbahram  9 місяців тому +1

      Typically your layout is a server component that gets rendered once and remains the same when user navigates. The template on the hand will re-render every time because it uses a `key` prop. The template doesn't need to be a client component necessarily. I turned it into a client component in this example because I was using framer motion, but you don't need to.

  • @samislam2746
    @samislam2746 9 місяців тому +1

    The mouse pointer in the video is not visible

    • @hamedbahram
      @hamedbahram  9 місяців тому +1

      Yeah when I switch screens the mouse hides. I'll have to remember to click on tabs before pointing at different things on the page. Thanks for the feedback.

  • @Felipe-pb9gu
    @Felipe-pb9gu 10 місяців тому +1

    Loving your videos, great content and well explained. Have a question, if you convert the template or the layout into a client component will all the childrens be client components too?

    • @hamedbahram
      @hamedbahram  10 місяців тому

      Thank! Glad to hear that. Re your question: only if you import a server component inside a client component will they turn into client components. You can pass server components as children as I did in the video without effecting the server-client boundary. Let me know if that's clear.

  • @LorenzoSemorile
    @LorenzoSemorile 7 місяців тому +1

    Hi, thanks for the video. I was trying to use template "server side" but unfortunatly when you navigate with LInk component, the template it seems no refresh some other ""server side" component inside. Why? Thanks for the answer.

    • @hamedbahram
      @hamedbahram  7 місяців тому +1

      The template itself would re-render on every navigation but the server components inside are cached by default. There are different ways to opt your page components into dynamic rendering, but the easiest way is to use the `noStore` function. You can read about it here → nextjs.org/docs/app/api-reference/functions/unstable_noStore

    • @LorenzoSemorile
      @LorenzoSemorile 7 місяців тому +1

      @@hamedbahram thanks a lot. I will try tomorrow and i will let you know. Sorry I’m learning nextjs framework in theese days. Thanks for your videos.

    • @hamedbahram
      @hamedbahram  7 місяців тому +1

      @@LorenzoSemorile Glad to help!

  • @t2e0j0a4
    @t2e0j0a4 7 місяців тому +1

    Hi really loved video. By the way what is the font u are using for VS Code editor

    • @hamedbahram
      @hamedbahram  7 місяців тому

      Thanks! I'm using Operator mono.

  • @raymondmichael4987
    @raymondmichael4987 10 місяців тому +1

    Thanks buddy 😊

  • @mahmoudmohamed-xu2lb
    @mahmoudmohamed-xu2lb 10 місяців тому +1

    so , we should use template to add exit route animations
    i tried it but it dosen't work what key should i pass to AnimatePresence
    and Thanks hamed for your amazing content

    • @hamedbahram
      @hamedbahram  10 місяців тому

      Yeah that should work, you can use any unique random key or the current path as the key.

  • @RicardoBarbosaSousa
    @RicardoBarbosaSousa 10 місяців тому +1

    Could you u use dark theme in the browser as well? 😊

    • @hamedbahram
      @hamedbahram  10 місяців тому +1

      I'll try it next time 🙂

  • @AllahomAnsorGaza
    @AllahomAnsorGaza 6 місяців тому +1

    how to pass data we fetched in layout to children pages

    • @hamedbahram
      @hamedbahram  6 місяців тому +1

      Not a straight forward way to do that, but you don't need to pass props, just re-fetch your data on the page as well, and React will de-duplicate the request.

    • @AllahomAnsorGaza
      @AllahomAnsorGaza 6 місяців тому +1

      you are great teacher ☺️
      thanks for all of your efforts

    • @hamedbahram
      @hamedbahram  6 місяців тому

      @@AllahomAnsorGaza Thank you! I appreciate that.

  • @moazamdev
    @moazamdev 8 місяців тому

    Does the template force the component to re-render?

  • @tuRistst
    @tuRistst 9 місяців тому

    But if I want to hide the header for about page?

    • @hamedbahram
      @hamedbahram  9 місяців тому

      Then don't put it in that route group.

    • @tuRistst
      @tuRistst 9 місяців тому

      Thanks, but I found a solution using Route Groups

  • @SanderCokart
    @SanderCokart 10 місяців тому +1

    I hope fixing exit animations on Templates is high on their roadmap, forced to use pages router for page animations

    • @hamedbahram
      @hamedbahram  10 місяців тому +1

      Hmm 🤔 didn't know there is a problem with exit navigation! I'll give it a try. Thanks for sharing.

    • @SanderCokart
      @SanderCokart 10 місяців тому +1

      @@hamedbahram templates document the use of exit animations but framer motions Animate Presence doesn't work with this because page is not the direct ancestor of the template

    • @hamedbahram
      @hamedbahram  10 місяців тому

      @@SanderCokart That's right. I just tested this, and while the exit navigation doesn't run, you can still animate the page. I changed the `main` tag that wraps the page in my template to `motion.main`

    • @SanderCokart
      @SanderCokart 10 місяців тому

      @@hamedbahram yes only initial and animate. Pages router is required till then.

  • @namesare4fools
    @namesare4fools 9 місяців тому

    your tutorial is excellent but i think content like this can be shorten to at most 10 mins

    • @hamedbahram
      @hamedbahram  9 місяців тому

      Thanks for your suggestion.

  • @sharpesthawk
    @sharpesthawk 8 місяців тому +1

    You are *"Jeff Goldblum"* right? Am I the only one who thinks that?

  • @deepaksingh-qd7xm
    @deepaksingh-qd7xm 4 місяці тому

    not good explanation