How to create conditional headers in nextjs

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

Web Dev Cody

Web Dev Cody

Ай бұрын

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 Ай бұрын
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 Ай бұрын
agreed!
@mattd5419
@mattd5419 Ай бұрын
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.
@DouglasSouza-te9bt
@DouglasSouza-te9bt Ай бұрын
It would be cool to bring a video showing how you configure your vscode
@CookerSingh
@CookerSingh Ай бұрын
Cody please review React 19 and how can we get the same performance out of it as nextjs.
@nekotajni394
@nekotajni394 Ай бұрын
How did you add that loading bar on top of the page with nextjs?
@WebDevCody
@WebDevCody Ай бұрын
It’s an npm module called toploader
@tmanley1985
@tmanley1985 Ай бұрын
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 Ай бұрын
You have to make a new stripe account for each website, but all of those accounts are linked to my LLC
@tmanley1985
@tmanley1985 Ай бұрын
@@WebDevCody That's what I was thinking. I really appreciate the prompt response!
@jitx2797
@jitx2797 Ай бұрын
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 Ай бұрын
Use NoStore on pages or functions that fetch data from the db
@kale_bhai
@kale_bhai Ай бұрын
I tried both, and I prefer Nested/Grouped Layout
@rasclatupon
@rasclatupon Ай бұрын
Hey Cody - what's this VS Code theme called? Thx
@DouglasSouza-te9bt
@DouglasSouza-te9bt Ай бұрын
bearded theme - stained blue and the icons is bearded icons
@SeibertSwirl
@SeibertSwirl Ай бұрын
You’re doing great sweetheart ❤
@WebDevCody
@WebDevCody Ай бұрын
Thank you sexy 😘
@emreq9124
@emreq9124 Ай бұрын
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
@Luisllaboj19
@Luisllaboj19 Ай бұрын
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 Ай бұрын
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 Ай бұрын
@@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.
@ShivGamer
@ShivGamer Ай бұрын
Hey Cody, How do you manage authentication and authorization for this project?
@WebDevCody
@WebDevCody Ай бұрын
Next auth
@ShivGamer
@ShivGamer Ай бұрын
@@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
@Yusuf-ok5rk
@Yusuf-ok5rk Ай бұрын
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 Ай бұрын
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 Ай бұрын
@@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.
@excalibur2417
@excalibur2417 Ай бұрын
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 Ай бұрын
For real, this simple functionality becomes super annoying to implement
@user-hf4lf6er1u
@user-hf4lf6er1u Ай бұрын
Hello
@albertilagan
@albertilagan Ай бұрын
(public) publicRoute1/ publicRoute2/ (private) privateRoute1/ privateRoute2/ maybe?
@WebDevCody
@WebDevCody Ай бұрын
Yeah that would work as well
10 common mistakes with the Next.js App Router
20:37
Vercel
Рет қаралды 184 М.
Why I still choose next.js
19:39
Web Dev Cody
Рет қаралды 16 М.
小女孩把路人当成离世的妈妈,太感人了.#short #angel #clown
00:53
She ruined my dominos! 😭 Cool train tool helps me #gadget
00:40
Go Gizmo!
Рет қаралды 54 МЛН
OMG🤪 #tiktok #shorts #potapova_blog
00:50
Potapova_blog
Рет қаралды 12 МЛН
Watermelon Cat?! 🙀 #cat #cute #kitten
00:56
Stocat
Рет қаралды 38 МЛН
Shadcn + Next.js 13 is HEAVEN | A QUICK GUIDE
13:30
developedbyed
Рет қаралды 124 М.
NextJS + State Management = Good Idea???
41:08
Jack Herrington
Рет қаралды 97 М.
Next.js with React Testing Library, Jest, TypeScript
25:04
Dave Gray
Рет қаралды 53 М.
State Managers Are Making Your Code Worse In React
13:33
Web Dev Simplified
Рет қаралды 156 М.
Serverless might bankrupt you (and how to deploy to a VPS instead)
14:26
Next.js App Router: Routing, Data Fetching, Caching
14:32
Vercel
Рет қаралды 294 М.
10 Tailwind Classes I Wish I Knew Earlier
13:31
Web Dev Simplified
Рет қаралды 164 М.
Learn NextJS's Superpower ISR in 15 Minutes
15:35
Josh tried coding
Рет қаралды 35 М.
How I like to implement role based authorization in Next.js apps
5:43
小女孩把路人当成离世的妈妈,太感人了.#short #angel #clown
00:53