How to create conditional headers in nextjs

  Рет қаралды 5,448

Web Dev Cody

Web Dev Cody

29 күн бұрын

My Products
📖 ProjectPlannerAI: projectplannerai.com
🤖 IconGeneratorAI: icongeneratorai.com
📝 ThumbnailCritique: thumbnailcritique.com
Useful Links
💬 Discord: / discord
🔔 Newsletter: newsletter.webdevcody.com/
📁 GitHub: github.com/webdevcody
📺 Twitch: / webdevcody
🤖 Website: webdevcody.com
🐦 Twitter: / webdevcody

Пікірлер: 33
@xya6648
@xya6648 28 күн бұрын
Nah bro don't say that you aint no noob! You are great! Thanks to you I learned a lot of things about Next.JS and IMO the most important part of my career was watching YOUR courses on S3 which helped me greatly!
@tsykin
@tsykin 28 күн бұрын
agreed!
@mattd5419
@mattd5419 28 күн бұрын
you are correct. nested layouts are the best way to achieve that. I would only use parallel routes for granular loading of multiple data in a page, or for modals, but not for static parts of a layout.
@emreq9124
@emreq9124 25 күн бұрын
I am developing mobile first app. So title on header may change depends on route and there is an general right button for some custom actions. So I make a generic layout component which takes headerProps and children as prop, so that we can give custom abilities to header on each page. I can use this template most of private pages like this: // here is page itself İf you have very dynamic header, you can also take header from props but jsx version. By using this version, youe layout component will put this header jsx to the right place(maybe header slot has max height or smth. This rule managed by layout ocmponent but header content will be rendered by page.tsx
@DouglasSouza-te9bt
@DouglasSouza-te9bt 28 күн бұрын
It would be cool to bring a video showing how you configure your vscode
@CookerSingh
@CookerSingh 28 күн бұрын
Cody please review React 19 and how can we get the same performance out of it as nextjs.
@kale_bhai
@kale_bhai 27 күн бұрын
I tried both, and I prefer Nested/Grouped Layout
@tmanley1985
@tmanley1985 28 күн бұрын
This isn't relevant to the video (great job btw!) but with all your side projects, do you run them out of multiple stripe accounts on the same llc? I've wondered about doing something like that myself.
@WebDevCody
@WebDevCody 28 күн бұрын
You have to make a new stripe account for each website, but all of those accounts are linked to my LLC
@tmanley1985
@tmanley1985 28 күн бұрын
@@WebDevCody That's what I was thinking. I really appreciate the prompt response!
@nekotajni394
@nekotajni394 28 күн бұрын
How did you add that loading bar on top of the page with nextjs?
@WebDevCody
@WebDevCody 28 күн бұрын
It’s an npm module called toploader
@jitx2797
@jitx2797 28 күн бұрын
Cody how do you handle caching? For every page i have added force dynamic and revalidat =0 but i want to take adv of caching
@WebDevCody
@WebDevCody 28 күн бұрын
Use NoStore on pages or functions that fetch data from the db
@rasclatupon
@rasclatupon 28 күн бұрын
Hey Cody - what's this VS Code theme called? Thx
@DouglasSouza-te9bt
@DouglasSouza-te9bt 28 күн бұрын
bearded theme - stained blue and the icons is bearded icons
@Luisllaboj19
@Luisllaboj19 28 күн бұрын
Maybe you could use a single layout if you make the component a client component, with the usePathname() hook from next you can check for the pathname and conditionally pass the different links to the component. Maybe keep the nested layouts when you actually need to add new layout on top of the previous layout.
@WebDevCody
@WebDevCody 28 күн бұрын
My issue is my header needs server component links. I guess I could just pass in the server component regardless and just not render it depending on the path. I’m still trying to figure out the best way to achieve this. I tried with parallel routes as well but it also feels hacky
@hakanberat
@hakanberat 23 күн бұрын
@@WebDevCody I am working on exactly the same case in my current team. First of all, thank you very much for opening my horizons. I wonder why you need to use the link components on the server side? I'm trying to do the conditional header rendering on the server side because I feel it will be more valid, but as you know, I'm not very convinced and in some cases I can't find a solution. Hope to hear your ideas on this subject and your new approaches in the future.
@Yusuf-ok5rk
@Yusuf-ok5rk 28 күн бұрын
but the tradeoff is, it full refreshes switching, doing that for the main layout. is it not better to just get pathname and show header in layout accordingly?
@yassinesafraoui
@yassinesafraoui 28 күн бұрын
I don't think it refreshes when you switch between routes that have the same header, but for other ones yes probably it would refresh but that's fine not a bit deal ig. For the pathname thing, I don't think that's the recommended way to do it even if it could work, the whole idea behind the app router is to not have to deal with routes yourself through pathname and stuff like that and let nextjs manage that for you, i guess one of the reasons is that your logic can easily break when you switch from dev to prod as your pathname changes from localhost to your domain name, it's probably doable it's just not as straightforward as letting nextjs manage that
@Yusuf-ok5rk
@Yusuf-ok5rk 28 күн бұрын
@@yassinesafraoui it does full refresh if those are both main layouts defined in the (group 1)/layout, (group 2)/layout thing. but this is true only for using more than 1 main layouts. nextjs app folder is so quirky tbh but at least it is well documented.
@ShivGamer
@ShivGamer 28 күн бұрын
Hey Cody, How do you manage authentication and authorization for this project?
@WebDevCody
@WebDevCody 28 күн бұрын
Next auth
@ShivGamer
@ShivGamer 28 күн бұрын
@@WebDevCody Cool man, thanks. Also do you have a discord or any platform where I can ask doubts from anyone in the community? EDIT: I joined the discord :D
@excalibur2417
@excalibur2417 28 күн бұрын
It's just unfortunate that Next.js doesn't provide a straightforward way to retrieve the current route on the server and conditionally render components like the header in the root app layout. This would greatly simplify things and is a feature many developers have requested, as evidenced by the numerous complaints in their repo issues. Hopefully, future versions of Next.js will address this gap to enhance routing flexibility and developer experience.
@WebDevCody
@WebDevCody 28 күн бұрын
For real, this simple functionality becomes super annoying to implement
@SeibertSwirl
@SeibertSwirl 28 күн бұрын
You’re doing great sweetheart ❤
@WebDevCody
@WebDevCody 28 күн бұрын
Thank you sexy 😘
@user-hf4lf6er1u
@user-hf4lf6er1u 28 күн бұрын
Hello
@albertilagan
@albertilagan 28 күн бұрын
(public) publicRoute1/ publicRoute2/ (private) privateRoute1/ privateRoute2/ maybe?
@WebDevCody
@WebDevCody 28 күн бұрын
Yeah that would work as well
10 common mistakes with the Next.js App Router
20:37
Vercel
Рет қаралды 173 М.
My best advice for finishing projects
8:41
Web Dev Cody
Рет қаралды 13 М.
Cat story: from hate to love! 😻 #cat #cute #kitten
00:40
Stocat
Рет қаралды 12 МЛН
Indian sharing by Secret Vlog #shorts
00:13
Secret Vlog
Рет қаралды 46 МЛН
ХОТЯ БЫ КИНОДА 2 - официальный фильм
1:35:34
ХОТЯ БЫ В КИНО
Рет қаралды 2,2 МЛН
어른의 힘으로만 할 수 있는 버블티 마시는법
00:15
진영민yeongmin
Рет қаралды 6 МЛН
Fetching Data Doesn't Get Better Than This
6:58
Josh tried coding
Рет қаралды 57 М.
How This Test Saved Kent’s Site
7:04
Web Dev Simplified
Рет қаралды 67 М.
Are we going back to PHP with fullstack JavaScript?
9:57
Maximilian Schwarzmüller
Рет қаралды 103 М.
the reality of building a startup as a solo developer
16:39
Jacob Sucks At Code
Рет қаралды 14 М.
Updates Like These Make Tailwind So Fun
8:00
Josh tried coding
Рет қаралды 69 М.
CSS Is 2.4x Slower Than Inline Styles (Oh No...)
19:39
Theo - t3․gg
Рет қаралды 68 М.
Goodbye Nextra
7:00
Web Dev Cody
Рет қаралды 6 М.
We Fixed Environment Variables
7:27
Theo - t3․gg
Рет қаралды 60 М.
How I setup role based authorization Next Auth
6:59
Web Dev Cody
Рет қаралды 9 М.
Cat story: from hate to love! 😻 #cat #cute #kitten
00:40
Stocat
Рет қаралды 12 МЛН