Learn useContext In 13 Minutes
Вставка
- Опубліковано 15 чер 2024
- 🚨 IMPORTANT:
Full React Course: courses.webdevsimplified.com/...
1 Year Free Hosting: www.atlantic.net/webdevsimpli...
Use code KYLE for an additional $50
In this video I cover everything you need to know about the useContext hook. I go over all the main use cases for useContext as well as many common mistakes that developers make. This is part of a series of React videos where I cover all the important hooks in React.
📚 Materials/References:
useContext Blog Article: blog.webdevsimplified.com/202...
React Hooks Playlist: • React Hooks
🧠 Concepts Covered:
- How to use hooks in React
- How to use context values in React function components
- How to use the useContext hook
🌎 Find Me Here:
My Blog: blog.webdevsimplified.com
My Courses: courses.webdevsimplified.com
Patreon: / webdevsimplified
Twitter: / devsimplified
Discord: / discord
GitHub: github.com/WebDevSimplified
CodePen: codepen.io/WebDevSimplified
#ReactJs #WDS #useContext
In order to simplify it, I think you could create an object, like const values = { darkTheme, toggle } and pass both values inside the ThemeContext.Provider, in order to avoid creating 2 providers.
Yeah you r right
These 13 minute videos end up taking me 2 hours to go through
Same here
I watched Mosh's 2 hour tutorial video and it took me 4 days.
lol i thought I was alone in this! I definitely set my pomodoro to watch this then do some practice problems then 25min later I was like wow I'm only like 5min into the video
still learning a lot though, just slow n steady
@@tvguideondemand mosh videos are normmaly very detailed and so it makes sense you took so long ;-)
Thanks a lot kyle :) I have seen so many videos of useContext hook but never seen this kind of a structure which is awesome to maintain and scale. This is gold.
After watching this video, I refactored one of my side projects, and it's so much cleaner.
Took me like 2 hours and 4 breaks to understand the refactor that you did in the separate file. I also didn't knew that useContext(ThemeProvider) was just like a consumer for function based components. Your tutorials are so amazing. What a neat way to write code, keep making good videos!
same here .. took me loads of time to get a grasp of this 8 min of 7zip video of something which is like a whole chapter
lol same
If it took you 2 hours to understand what he did then I guess maybe the explanation isn`t that amazing after all? 🤔
@@ronyfluk8396 By that logic, you can learn HTML, CSS, JS, React and Authentication in just 10 hours by watching one of the BootCamp videos on youtube. Practising and implementing stuff takes much longer than watching a video on it, no matter how good the content is.
@@ronyfluk8396 no. I thought that too but Web Dev Simplified is a great tutor. The problem is we are probably all programmers with different years of experience and understand the problem but React introduces a new way to tackle a problem that probably didn't really exist until you started using React. Most people think to switch themes, just have two css files and have some code to change the class of the body from light to dark..... and you can even use local storage to remember the users choice...
However if you use React, that solution may introduce other problems therefore useContext has to be understood.
The most informative channel I have found for web dev. Thanks again for clearing up another complicated topic so concisely.
Great video. I just started learning about useReducer and useContext. So perfect timing!!
This channel literally has everything that I search for. Can't thank you enough for sharing your knowledge!
This was another useful video from your channel. The first example of useContext in functional/class based components was easy. Second example was a but advanced but still easy to figure out and understand. Thanks for making such awesome content.
I can't believe how easy it is to understand it the way you explained it. Using your vids as a refresher (haven't done react in a while) and it's been super helpful for my job search. Not sure you're gonna read this but THANK YOU. Will take your full course
You are one of the best at being able to articulate advanced concepts in an easy-to-digest format. Living up to your name. I don't know where I would be without your lessons, you're literally godlike.
These are amazing thanks for making these, I am in a bootcamp at the moment and we are learning react. These help clear things up a ton so thank you for making these. Keep up the good work Kyle
How did life turnout after the bootcamp?
I have been waiting for this one for so long. Thanks a lot
After watching the entire video once, then duplicating the project during a second viewing, I was able to understand the concepts well enough to add additional context variables and new sibling components that can easily communicate amongst themselves. Your explanations, demos, and walk-throughs are so clear, concise, and to-the-point that with some study, the concepts really begin to sink in. Thank you!
etest
I think you can pass in not only state but also functions in the value attribute of the provider like this:
{children}
...and then just destructor the two depending on what you need in a particular component.
yeah, I was like that's really easy why we need another provider but he finds his way cleaner I assume.
which variable would you destructure? like usually for props it is const { state, function } = props. what would you use instead of props in our children components?
@@wizhaa useContext(name of your context)
@@wizhaa useContext(CanYouReadThat)
Yeah why would you wrap it around another provider. It messes the code
Your reactjs videos are the best! You explain so well and your examples are excellent. I understood this right away after being confused by someone else's vid
fantastic video! I am trying to combine this with your "useReducer" video right now for a somewhat complex bit of state management... I think a video like these combining the two concepts would be a smash hit my dude.
Amazing explanation. I've been able to refactor a complex, nested code using this pattern in minutes. Thank you !
I think the hardest part of this is that you are doing it with themes. If you were to simply expose an object or something and have it available in all of the children, it might be a little bit clearer. Using the theme is actually muddying up your demo.
Agree
Sorta agreed. Although theme here is just boolean value, but new comers need to wrap their head around this one more level
Absolutely, I just can't get my head around this explanation, going to need to check another vid
@@jtaylor8606 Hey check this video out. It helped me a bit better than this
ua-cam.com/video/hUhWtYXgg0I/v-deo.html
but what about updating it's value? How would you re-render the app?
I had to rewatch to fully get it, but it all makes sense now. Thanks mate! As always cristal clear explanations, keep up the great work!!
You're my hero at this point. I'm literally watching this while on the job.
Thank you! I was working on a little webapp and totally blanked on the pattern for creating the custom hooks (near the end of the video). You're awesome man 🎊☮️
Great Video about Context!
Im just disagreeing with creating multiple Contexts for a variable and its Setter function! You can just pass both as an object as the context value :)
I was also wondering why he didn't do this.
In your case, you are right. But think about you use styled-component's ThemeProvider which accepts only DefaultTheme, that is why nested provider is an option for this case.
This is so perfect. Exactly what I was looking for. Thank you :)
what are your thoughts on passing on the update theme function as a value to the original theme context? (instead of it being its own context provider)
I love this guy so much but he's persona is what I imagine an alien would create if they were trying to build a human
I've really come to like his personality and his method of explanation.
Right. His cadence sounds like it was the outcome of a deep learning algo.
Be greatful youngling, Kyles stormed Area 51, found alien tech, then set loose their clones to teach us all how to upgrade our world and get better paying jobs.
Why would an alien build a human is my question
are you all gays here lol
Wowwwwwww! I can finally understand this. Very well explained and broken down. I like how you explain from many different angles so you really get your point across
Just what I needed this Saturday morning, made my app work perfectly! ~ Thank You!
These hooks videos were just awesome. really easy to understand. Thank you so much
This is an absolutely fantastic tutorial 👏🏻
A gentle introduction to useContext and context in general. Two points:
As others have noted, I would have a single provider for both the darkTheme and toggleTheme values.
Also, I found it confusing that the button now has to live within the FunctionComponent. I'm not sure which is better: wrap the App component in ThemeProvider one level up, or create an intermediate component to hold the button and the FunctionComponent.
Amazing, I have a class yesterday about useContext, but now, after your video, I'm closer to be able to handle it!!
This is an awesome tutorial. I needed to watche 2 times but it's very clear how useContext works. Great, Kyle. Wish you all the best.
Simple and nice explanation of useContext. Thanks a lot Kyle for such a videos. Keep up good work!
Thanks a lot, you are an exceptional teacher and your code looks so clean!
I love your videos and I usually get it on the spot, but honestly this is the first time that it went straight over my head
This tutorial is highly recommended for anyone who needs to understand context API concepts, great Job KYLE ✨✨✨
Thank you so much! I recommend everyone to code along and examine to understand easier
Thank you so much for making these videos. My job is moving to react native from native mobile development and I have found these to be very helpful and even shared the playlist with my team.
As a react beginner I'm sure this is a great explanation for someone with a little more experience. As a beginner I found this example to much. Passing a variable down such as a name or number would have been a great start IMO. I hope this is constructive criticism. You channel is amazing!
there are no words to appreciate your explanation.. infinity hats off!!! God Bless!
Thanks for the simple and straight forward tutorial.
Thanks for the detailed explanation as always, very helpful
Well explained. This is the best explanation about useContext compared to all other videos in this subject. Thanks.
Thank you, Kyle! As always, clear, concise, and direct to the subject! 💯💥👋👌
so very helpful, just the right level of detail
Thanks for makes these things very easier for me. Love your content. keep it up.
Yo your youtube title is telling the truth!!! hands down the best version so far !!! thank you!
Thank you for the tutorial saved me a lot of time in my current project. God bless you.
This is Awesome! I’m totally going to make use this tomorrow. 👍🏾
Very nice. Easy to understand. Good example of context
Thanks kyle, your tutorial so simple i can easily understand 😄
Look forward for your courses Kyle!
Man, you are awesome. Your videos are so much helpful. God bless you.
Awesome video, I like how he increase the code without loosing the complexity understanding of the context.
This was hard to understand. So I made chatGpt write everything for me. Thank you kyle.
This is brilliant, thank you!
Hey old friend!
Your like a team mate who takes enough time to explain what we need for the sake of continue our work.
I always go back to this channel if there's any concept or JS feature that I don't really understand right after read hundreds of articles or blog publications. Thanks in advance.
Amazing explanation!! Thanks a lot.
I love your channel bro, keep up the good work!
Good stuff, great to get a deeper understanding of stuff I learn from The Odin Project from you on here!
awesome video, after seeing some articles on internet, this video helps me understand useContext in in only 13 minutes. thanks!
Great tutorial as usual. I have a question. Instead of creating another context if i pass toggleTheme in themeContext along with darkTheme value is there any problem??
Ver clearly explained. The concept is really drilled into my mind. thank you for this amazing video
Thank you! helped me a lot
can't thank you enough. got this to work in minutes
This is easily one of the most insightful videos about web dev I've ever seen. Not only because of the pattern it advances with useContext, but also for how well it illustrates the pursuit of encapsulation and ellegance. Kudos!
nothing elegant about it
Hatred is of no use to you or anyone else.
Exactly what I needed dude ty
Very good and consise explanation! Thanks for one more awesome tutorial!
This was a really good tutorial!
This was a great tutorial. This is something i will refer back to in the future
i am refering that to myself right now, for the third time in a week
Thanks Kyle for the context theme in React.
I love your way of teaching.. keep it up
I love Kyle's lessons, he's probably the one instructor on youtube that I don't get bored watching, but I can't be the one who watches his videos in 0.75 speed, dude be too quick with his logical structures as he speaks lol
great stuff! thanks a ton!
Not too sure I understand some of the negative comments, this was a super explanation of useContext and a perfect approach to allow token based security for react apps. Thank you!
I love it very neat! Thank you 🙏🏼
I literally spent hours yesterday to get this to work, I have terrible timing
😂 atleast you know now
useContext: I am gonna destroy this man(Redux)'s whole career.
Kyle you are the man, I can already see you as the top developer trainer in the world!
wow, this is exactly how the mui built their theming. Thank you for the explanation before that I was struggling to understand it.
Thanks a lot for being my mentor
Great video! Thanks :D
You're great :-) Excellent, clear explanation, and I was able to put it to use right away.
This video has saved my hide! Thanks Kyle.
This assumes you know what a context is and how in general it's being used. i.e., not for beginners.
I agree, tbh this is not really a tutorial more like watching someone code while somewhat explaining his thought process.
literally 90% of all tutorials assume you are a beginner and I'm getting fucking tired of it... I find intermediate or advanced tutorials such as these very refreshing and sadly they are quite rare...
@@IncomingLegend Me too bro. Tech With Tim has done some nice intermediate and expert python playlist and also object oriented design were he doesnt treat you like a begginner. You may want to check him out
Trust me, come back to this when you need a quick refresher and you'll love how concise this is.
Thank you for helping me reduce my codebase, great video!
Great video. Thanks. When you 'take it a step further' around 5:45, I had to re-watch a few times. LOL. My brain shut down the first time watching. I guess, I was still processing the first 5 minutes.
I love your channel, Keep up your work please make one video on "Event Loop"
great video! thanks a lot
Love the video. Thanks for the wondeful contribution. If I wanted to use an external stylesheet in js react native, could context be applied? Not quite sure how that would work? Would love to hear from you. Thanks again for your fantastic work!
Can someone explain why App doesn't have access to context? If we leave the button in the App and import the same custom hooks as in the FunctionContextComponent, the application will not work. Why?
This is really clear and good guide to this. Though I went through a react course and have solid fundamentals so there is a bias
Great video, many thanks for sharing this.
Thanks Kyle some deep explanation there
Amazing explaination
Pretty awesome video. Thanks.
Wow, finally I got how it works :D
Thank you, Kyle!
My brain's gonna blow up. But now I should do the same alone as we all together did here :D
Correct me if I'm wrong, but why do you need to create a second Context for updating? Can't you simply pass in the update function along side darkTheme in Value? I've seen multiple other videos where they do just that
Thank you for this knowledgeable video.