I've watched or read a BILLION tutorials on Context API in React and this is the only one that made enough sense to get it working and more importantly to understand it, while converting it to my use case! You're a champion!
@codewithguillaume7 ай бұрын
Oh dude your message means so much to me… thanks. If you want to go deeper I am launching a plat for soon : thedevelopercourse.com ! Best
@djribs6 ай бұрын
I spoke too soon! It seems I've done something incorrectly because no matter where I try to set the context, the default value never changes when trying to read it. I was of the understanding that wrapping the RootLayout of the app in the context as you've described in your video would allow it to be consumed by all components and their children since everything is a descendant of RootLayout. Any idea what could be wrong?
@djribs6 ай бұрын
Turns out it was working after all! I wasn't actually using the context value yet. I was trying to console.log its value to confirm it worked, which kept showing the default value. When I actually used the value in another component it worked. It seems console.log always shows the default value, though I have no idea why!
@Juajuaa186 ай бұрын
Correct me if I'm wrong (I'm learning server side components). If you 'use client' on root layout, then your whole application will be client side only and you won't be able to use any server side components or rendering, right?
@mohamedtsx6 ай бұрын
Your explanation is great! You start with a single piece, and if it's okay, let's see another one. Thanks a lot!
@codewithguillaume6 ай бұрын
Thanks my friend ! Discord if you want to join dub.sh/codewithg-discord
@zhongyou9166 ай бұрын
Your tutorial is very easy to understand. I've read many other articles and couldn't understand. thanks a lot.
@ryumarukurozaki72457 ай бұрын
You're the best! this helped me for my personal project! keep making videos!
@codewithguillaume7 ай бұрын
Yesssss !
@polidahiya90246 ай бұрын
using context api like this i don't think there is any use of using next js over react , now the whole application is a client component
@jordanboutrois15848 ай бұрын
Hi, I'm asking a question, you're declaring your context provider near to the root of application, so Is each children which passed into Provider are client components? and therefore Doesn't this prevent us from taking advantage of the server components? (Thanks for the video, great job)
@djribs7 ай бұрын
Look up "interleaving" in React. The short answer is no, they all won't become client components from putting context at the root.
@staromofficial5 ай бұрын
no, read nextjs docs, they have explained it, when u wrap with cleint componet it does not make its childs a cleint component . They still treated or used as server component
@DhaouJawhar5 ай бұрын
just what I needed, thank you so much!! ♥
@lukeparker60266 ай бұрын
Thank you for creating this video!
@codewithguillaume6 ай бұрын
No problem Luke I hope you find your responses
@ajaljose26906 ай бұрын
At last something that worked for me. thank you :)
@codewithguillaume6 ай бұрын
Nice join my discord 😉
@memoryclips.moment3 ай бұрын
I relly like the way he teach it can't be easier than this tnx 👍
@felipeconceicao44655 ай бұрын
Amazing video, thank you so much. Best wishes from Brazil
@Dana-Baiardi8 ай бұрын
you did it so easy!!! :) loved it! It worked fabulous!!
@codewithguillaume8 ай бұрын
Amazing! Glad it helped you 😉👍
@DePhpBug2 ай бұрын
Thanks the author of this youtuber , the content helps me alot. Don't stop producing great content , keep it up (y)
@IbrahimSowunmi-sp4qs4 ай бұрын
Huge video, thank you!
@rogeriolimas5 ай бұрын
Great video! Thank you!
@TarasDyda4 ай бұрын
What is the use of NextJS if it renders the content on the client side?
@tekskilldev83106 ай бұрын
Beautifully explained. However, I have done the same i.e. providing context to all components(sharing provider) by following next ui method. That method is install nextui and create a provider.js file within the app folder. This provider works as wrapper which is then imported in the layout.js file wrapping all components in the layout including navbar you create within the layout file. I think this eliminates the need of src folder and need to use useContext function and all other context creation. See if you agree?
@ivannavas86205 ай бұрын
Thanks so much, just the video i needed 👏
@guvenfazli5 ай бұрын
Thank you so much, i finally got it.
@mtspivato5 ай бұрын
great content!
@kmplus3608 ай бұрын
I am a new subscriber. Thank you very much for the content
@codewithguillaume8 ай бұрын
Welcome and thank you my friend !
@sergio058-pb6hf11 ай бұрын
just what I needed, thank you so much!!
@techug27195 ай бұрын
So, my question is on the metadata, i export my metadata from the root layout.tsx, making the root layout client doesn't allow me to export this metadata, how would you go about this?
@Xurshid_Yoldoshev4 ай бұрын
thanks from uzbekistan
@codewithguillaume4 ай бұрын
Thanks man !
@Ziad-Al6 ай бұрын
great explanation, thank you, how about if we want to use the name and useName inside a page which is server component or simply not declared as "use client"?
@Sniksax10 ай бұрын
Merci Guillaume, t'es le meilleur !
@codewithguillaume10 ай бұрын
Merci Mohamed !
@violinsheetmusicblog7 ай бұрын
Why do you define the state twice? Once in useState() and another time in createContext()? Seems redundant, not sure why it is necessary Oh I guess it's because AppContext can be used on its own without the component
@codewithguillaume7 ай бұрын
Yes
@LorenzoSemorile8 ай бұрын
Great video. Thanks so much. When i try to use the contextProvider in a server component, my app goes in a infinite loop. Any suggest?
@pauliusm27358 ай бұрын
God bless and ty!
@pnh.23147 ай бұрын
Best explained 🤌
@samuelizevbizua10 ай бұрын
God bless you brother. Really helped
@codewithguillaume10 ай бұрын
Thanks my friend
@altafansari7527 ай бұрын
But if you wrap the server side component inside the Client component then all the server components serve as client components?
@Nscb19477 ай бұрын
no
@Juajuaa186 ай бұрын
@@Nscb1947 why not? if root layout is client component, then all of it's children are client too. Am I wrong? Please correct me if I am, I'm learning about server side components.
@IAmMrLiverpool8 ай бұрын
Hi, thx for your work. Can I ask which theme you use for vscode (and which icons). thanks in advance
@codewithguillaume8 ай бұрын
Tokyo night storm 😉
@sofianealloui2 ай бұрын
thank you so much sir you're a legend, ChatGPT wasn't helping with this
@edgardejesusmendozaortegon765511 ай бұрын
Thanks teacher!!!! Excelent video!!!!
@Eye9744 ай бұрын
thx
@LeonardoLuzx4 ай бұрын
in this way was not possible to use generateStaticParams, thats a server component function.
@frenchmike6 ай бұрын
but isn't it bad to make the root layout a "use client" ? also won't it make everything downstream a client component and page ?
@codewithguillaume6 ай бұрын
Yep depends on what you want
@VadimBogomazov7 ай бұрын
What is I want to set metadata in layout file? If I put "use client" it is not gonna work
@joao-pedro-alves9 ай бұрын
Well, that's a good workaround to work with contexts but an annoying problem about that approach is that all components which are going to use the context need to be client-side. components client side can't be async. So, in my case I'm trying to share to all components the current locale to implement i18n but i need to use an async useTranslation hook and this approach fails in this case, a very common case btw
@codewithguillaume9 ай бұрын
Absolutely, it really depends on how you want to build your app: client or server. On next examples I’ll explain more 😉
@galaxian93938 ай бұрын
You should "use client" in the context file, isn't it ?
@rykageee8 ай бұрын
Hey :) can you do a demonstration on how to do NextJS global context with XState Machine?
@leandrojuarez17948 ай бұрын
Nice video
@les68374 ай бұрын
bro how did you put layout as use client??
@awais_ansarii5 ай бұрын
❤
@codewithguillaume5 ай бұрын
Thanks my friend
@bujerolandia7 ай бұрын
Great content bro! Your video really helped me to set a global context for my app very easily and fast! Using NextJs 14 and Ts