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
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!
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.
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.
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.
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.
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?
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.
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.
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
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
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.
@@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
@@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`
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
Thanks Kyle! I appreciate your comment, and I'm glad you're finding the videos helpful.
Finally I understood that, thank you! 🙂
Glad it helped!
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.
My pleasure! Glad it was helpful.
Again top notch content on NextJS
Thank you, keep it up 👍🏻
My pleasure!
Thank you Hamed, This video makes a lot of sense to understand between layout and template.
Glad it was helpful!
congratulation for reaching 10k subs well deserving, your content is really great explaing all the bits and pieces of front end development
Thanks! I appreciate it.
Thank you Hamed, It's been nothing but Imppactful and Growth since i subscribed to your channel
My pleasure! Glad to hear that.
Nice content. Thanks for explaining concept well
Glad it was helpful!
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!
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.
Thank you so much for your support and teaching, I'm really understanding your explanations.
You are very welcome. Glad to hear that!
You are a great instructor!
I appreciate that!
I thought it just like layout but this video is awesome. Got to know more about template' functionality
Glad it was helpful!
Clear and understandable examples. Thank you!
Glad it was helpful!
we would love a framer motion video with nextjs
Absolutely! That has been overdue. Will work on it.
clear explanation
Glad to hear that!
Thank you Hamed. I appreciate your fantastic tutorial
Anytime Hasan! I'm glad it was helpful.
congrats bro for the 10K, keep rocking :)
Thank you so much 😀
This is Gold
Thanks 🫡
Best regards from Egypt
Welcome to the channel!
Such a great explanation, Well done Hamed👏
Thank you! 🫡
beautifully explained
Thank you! 🙂
thank you
You're welcome
Thanks
Anytime!
Great tutorial ❤
Thanks! Glad you found it helpful.
🇳🇬 Great job
Thanks!
i have a login page (Auth pages) how can i remove the components in RootLayout in those pages
You can use route groups to create to different layout. Watch this → ua-cam.com/video/Go4rL15gYTs/v-deo.html
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.
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.
The mouse pointer in the video is not visible
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.
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?
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.
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.
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
@@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.
@@LorenzoSemorile Glad to help!
Hi really loved video. By the way what is the font u are using for VS Code editor
Thanks! I'm using Operator mono.
Thanks buddy 😊
Any time!
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
Yeah that should work, you can use any unique random key or the current path as the key.
Could you u use dark theme in the browser as well? 😊
I'll try it next time 🙂
how to pass data we fetched in layout to children pages
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.
you are great teacher ☺️
thanks for all of your efforts
@@AllahomAnsorGaza Thank you! I appreciate that.
Does the template force the component to re-render?
Yes exactly.
But if I want to hide the header for about page?
Then don't put it in that route group.
Thanks, but I found a solution using Route Groups
I hope fixing exit animations on Templates is high on their roadmap, forced to use pages router for page animations
Hmm 🤔 didn't know there is a problem with exit navigation! I'll give it a try. Thanks for sharing.
@@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
@@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`
@@hamedbahram yes only initial and animate. Pages router is required till then.
your tutorial is excellent but i think content like this can be shorten to at most 10 mins
Thanks for your suggestion.
You are *"Jeff Goldblum"* right? Am I the only one who thinks that?
I'm not that old 😅
not good explanation
Thanks!