Learn React Hooks: useContext - Simply Explained!

  Рет қаралды 113,157

Cosden Solutions

Cosden Solutions

11 ай бұрын

Join The Discord! → discord.cosdensolutions.io
Source Code → github.com/cosdensolutions/co...
In this video we will learn about React hooks, starting with useContext. This powerful React hook will allow you to manage your state efficiently without having to pass an enormous amount of props around (prop drilling). You will learn how to identify when to use the React Context API, how to use createContext to create the context, create a custom hook to handle undefined values, and finally use the context in any component to get access to the data.
In this new React world, hooks are here to stay, so it's best to learn them! In this tutorial I demonstrate the useContext React hook, and I explain it very simply and in a way that is easy to understand. Enjoy!

Пікірлер: 230
@cosdensolutions
@cosdensolutions Ай бұрын
Hey everyone! I just launched 🚀 Project React, which is a course that teaches you React by building a real-world project. It goes way beyond what you see in these videos and walks you through step-by-step on how to build a big and complex application with React! You can check it out here: cosden.solutions/project-react
@GeraldPajulas
@GeraldPajulas 4 ай бұрын
Thank you. I've been learning React for about 4 days and I was confused about the useContext and createContext, but your video explains it well. Thank you.
@shubhankarvalimbe5286
@shubhankarvalimbe5286 7 ай бұрын
Great tutorial! I was so confused about how Context works, every other creator complicates it too much. Thank you for simplifying it. Just subbed!
@cosdensolutions
@cosdensolutions 7 ай бұрын
makes me happy to hear!
@HR-pz7ts
@HR-pz7ts 2 ай бұрын
It's amazing you also taught how to deal with problems and showed proper way to code and handle potential errors.
@mikoajkulczynski5213
@mikoajkulczynski5213 6 ай бұрын
Thank you for the content. You have the gift to talk about coding in a simple way.
@cosdensolutions
@cosdensolutions 6 ай бұрын
thank you for the kind words!
@jijocleetus
@jijocleetus 4 ай бұрын
Great one with context, i like the way you handled the undefined scenario. Thanks for the tutorial.
@osmankain1508
@osmankain1508 Ай бұрын
Wow you're a perfect teacher and programmer thanks for the time that you spent for this amazing content
@camilotorresf1
@camilotorresf1 11 ай бұрын
This was a really good explanation. I took notes and later was able to replicate a similar example. I now understand the useContext hook a lot better. I'm just starting with React and this is really my first application, although I work with a team in a project that already have a lot of react. I expect to become more proficient in React to really be able to work on that project. Keep the good work, I hope you get a lot of subscribers soon.
@cosdensolutions
@cosdensolutions 11 ай бұрын
Really happy to hear that dude! You're going to do great ☺️ thank you for the kind words!
@lordkonadukweku6965
@lordkonadukweku6965 5 ай бұрын
@@cosdensolutions please when are going to do a video on HOC
@Chris-by8tg
@Chris-by8tg 3 ай бұрын
This was the clearest explanation I've seen. Thank you!
@marshallfungai3033
@marshallfungai3033 4 ай бұрын
Thanks man, been watching your videos for the last 7 days. Practicing for mid-senior dev job... Now I feel like a junior dev 😁, because of all the content I learnt. I "was" a "I can do it, but I can not explain it" person. But the upside is now I "REALLY" know what to do. Just subscribed. And we need more videos on testing.
@user-gm3lg8gp3m
@user-gm3lg8gp3m 9 ай бұрын
I subscribed!! This is a great way to explain the concept + thanks for adding the error handling part 👍
@cosdensolutions
@cosdensolutions 9 ай бұрын
🤙
@AntNZ
@AntNZ 11 ай бұрын
Wow! Such a excellent explanation and with examples too. Well done 👏👏👏👏
@cosdensolutions
@cosdensolutions 11 ай бұрын
Glad you enjoyed it! 🤙
@user-sy5fd7kn8w
@user-sy5fd7kn8w Ай бұрын
Hands down best explanation of the topic on the tube. Thank you!
@jay-kv6wn
@jay-kv6wn 11 ай бұрын
I hope your videos go viral soon like they should. You are doing a great work with your explanations
@cosdensolutions
@cosdensolutions 11 ай бұрын
Haha imagine going viral for React 😅 would love it!
@wekesirken6961
@wekesirken6961 4 ай бұрын
That was some good explanation, you made contexts seem obvious...Appreciated
@shawn.builds
@shawn.builds 18 күн бұрын
been loving the react tutorials man! dont think anyones ever explained context so simply :)
@XXlikeabauss
@XXlikeabauss 9 ай бұрын
Really helpful video, thank you so much!
@ThomasKanzig
@ThomasKanzig 7 ай бұрын
Amazing tutorial. Thanks a lot.
@garudaphoenix5479
@garudaphoenix5479 10 ай бұрын
Thanks for this great and clear explanation with a lot more edges. Hope you will get 1 million subs soon. Tbh, You deserve it.
@cosdensolutions
@cosdensolutions 10 ай бұрын
Thanks a lot 🤙
@sub_in01
@sub_in01 8 ай бұрын
Bro I really love your content and I learn a lot from you, don't worry about subscribers, they will ultimately come to you as your way of explaining is so very good. Keep uploading contents.
@cosdensolutions
@cosdensolutions 8 ай бұрын
thanks for the kind words! 🤙
@YisneySoto
@YisneySoto 7 ай бұрын
Great, thanks. It's my first Context video and I think I got it at the first time because it's so well explained, of course having used Redux before makes this easier to understand.
@cosdensolutions
@cosdensolutions 7 ай бұрын
glad to hear it!
@kwasiezor1630
@kwasiezor1630 11 ай бұрын
Thanks for the video bro. Simplified explanation always makes understanding better 😊
@cosdensolutions
@cosdensolutions 11 ай бұрын
Glad you found it useful!
@kwasiezor1630
@kwasiezor1630 11 ай бұрын
Yes Indeed. Keep it up 👏
@vampirekabir
@vampirekabir 10 ай бұрын
trying to get a grasp of it,nobody taught like u did,i finally get it now ❤❤
@cosdensolutions
@cosdensolutions 10 ай бұрын
🤙
@Shaheer-xs5os
@Shaheer-xs5os 9 ай бұрын
That was such an awesome explanation 👍
@cosdensolutions
@cosdensolutions 9 ай бұрын
Thanks 🤙
@simplebutcorrect6176
@simplebutcorrect6176 7 ай бұрын
Bro I love the way that you explain keep it up. Subscribed❤
@joshuaagudelo29
@joshuaagudelo29 8 ай бұрын
Well explained!
@rmc1579
@rmc1579 4 ай бұрын
great explanation. I was a little bit confuse when using context and how to implement them.
@ooorayooonyoooo
@ooorayooonyoooo 10 ай бұрын
A really underrated channel, well done bro! ⚡❤
@franbrankovic3617
@franbrankovic3617 7 ай бұрын
After this video you really don't need to watch another video about react useContext. This was excellent video.
@sup_nim
@sup_nim 8 ай бұрын
great explaination thank you bro!
@mchisolm0
@mchisolm0 27 күн бұрын
Definitely appreciate your attention to detail and have earned my sub. You helped me understand how I was having trouble with a boilerplate I use that has a useState inside a useEffect. I understand *what* the problem is now (thank you for that video), but I can't figure out what I need to learn to solve it. Thanks for at least helping me get closer.
@sudiptobose8296
@sudiptobose8296 2 ай бұрын
Fantastic tutorial. I really appreciate it. 😊
@leonardmbibi8013
@leonardmbibi8013 7 ай бұрын
Top notch! You're the man
@glenmccallum7051
@glenmccallum7051 7 ай бұрын
Thanks a lot, this was really helpful. Really great video and great channel
@cosdensolutions
@cosdensolutions 7 ай бұрын
glad it helped!
@AhmedHuzain
@AhmedHuzain 4 ай бұрын
"If you watch this hook video, you'll probably never need to watch another" This is so true! You explain it so well. Thank you!
@antimrevapati8992
@antimrevapati8992 3 ай бұрын
Great Explanation, Thank you!
@syedayanata9765
@syedayanata9765 7 ай бұрын
I watched many videos and still did not understand context but this video helped me a lot.
@cosdensolutions
@cosdensolutions 7 ай бұрын
you got this
@Teddyrobinson
@Teddyrobinson 3 ай бұрын
Another great tutorial thanks so much!
@user-dm3sf9mk2o
@user-dm3sf9mk2o 7 ай бұрын
This was a really good explanation. Would you consider doing a video about useContext in regards to forms?
@cosdensolutions
@cosdensolutions 7 ай бұрын
sure!
@user-dm3sf9mk2o
@user-dm3sf9mk2o 6 ай бұрын
@@cosdensolutionsI get stuck on passing input content to the page. Trying different ways without too much success.
@sathirabandara7981
@sathirabandara7981 3 ай бұрын
Great job man. its very helpful !!
@UnfinishedYara
@UnfinishedYara 3 ай бұрын
Thanks man! Crystal clear now!
@myothiha1168
@myothiha1168 9 ай бұрын
best explanation ever!🤩
@thebeastsclips
@thebeastsclips 5 ай бұрын
useContext is a great alternative for a bunch of prop drilling with a bunch of useStates as well in the child component as well.
@Vishal360
@Vishal360 7 ай бұрын
loved ur react tuts.... 🔥🔥🔥🔥🔥🔥🔥🔥
@deshannawarathna6283
@deshannawarathna6283 4 ай бұрын
Thank you man. That is good explanation
@lordkonadukweku6965
@lordkonadukweku6965 5 ай бұрын
Top-notch explanation. Manifesting 100k subscribers by end of this year
@Fleischmann773
@Fleischmann773 7 ай бұрын
Great example!!!
@mgx49
@mgx49 2 ай бұрын
No doubt I won't need to watch another React Context API video! [Subscribed]
@samahgad241
@samahgad241 4 ай бұрын
Realy great explanation,thank you
@HerlonCosta
@HerlonCosta 5 ай бұрын
I reall like this explanation. You're very good, god bless you!
@vivekkumar-pc1xy
@vivekkumar-pc1xy 5 ай бұрын
Crystal Clear... Thanks
@marceloleoncaceres6826
@marceloleoncaceres6826 4 ай бұрын
Great video, thanks for sharing your time and knowledge,
@poornasaipilla1620
@poornasaipilla1620 2 ай бұрын
Really use full video thanks for doing ... extending my great full and encouragement .... keep doing well..
@israelkayaba6002
@israelkayaba6002 5 ай бұрын
Thanks bro, much appreciated !
@Martin-xf8be
@Martin-xf8be 5 ай бұрын
That subscribe intro you did made me subscribe. Genius.
@tokaqarcivadze5825
@tokaqarcivadze5825 6 ай бұрын
the way you explain react is the best!
@theppiwatkomolwat4429
@theppiwatkomolwat4429 5 ай бұрын
1:31 This part of the code worked; I have now subscribed!
@cosdensolutions
@cosdensolutions 5 ай бұрын
☺️
@cypherop2608
@cypherop2608 4 ай бұрын
you made it soooooo easy to understand
@omkarjagtap2212
@omkarjagtap2212 2 ай бұрын
man, awosome video crystel clear concepts and learned how to write a more safe code(in the pov for debugging)
@antoninosartori
@antoninosartori 6 ай бұрын
And what if User comes from a fetch? Do you put in on the custom hook? How would you handle errors? Thanks for the video
@hanguyenmanh2459
@hanguyenmanh2459 5 ай бұрын
If user come from server state, don't throw error in custom hook, just return user.
@ihebbenaicha1353
@ihebbenaicha1353 11 ай бұрын
please keep it up with more hooks and thank you !
@cosdensolutions
@cosdensolutions 11 ай бұрын
Will do!
@user-ms4cs3cb4w
@user-ms4cs3cb4w 4 ай бұрын
Thanks it was very helpful
@RyS29
@RyS29 5 ай бұрын
Great content, thank you!
@theGameThrough
@theGameThrough 10 ай бұрын
It would be suggested to put some console log and also the UI just to make it more clear would be a lot helpful too thanks
@dobindahoria4633
@dobindahoria4633 8 ай бұрын
this is gold
@awasum
@awasum 3 ай бұрын
Thank you very much. Good content
@rasikakshirsagar5563
@rasikakshirsagar5563 3 ай бұрын
Thank you bro!
@thesnowqueen98
@thesnowqueen98 8 ай бұрын
Could you tell the name of the VS Code Theme you are using?
@qweqw1359
@qweqw1359 9 ай бұрын
Nice 👍
@Pareshbpatel
@Pareshbpatel 6 ай бұрын
Context API with a custom hook, so well explained. Thank you. {2023-10-16}
@mahdighasemi9518
@mahdighasemi9518 8 ай бұрын
Thanks a lot.
@user-el9ui5jk5m
@user-el9ui5jk5m Ай бұрын
I literally subscribed after seeing your message in the Video
@brNoMundo123
@brNoMundo123 2 ай бұрын
Sou desenvolvedora Júnior e seus vídeos estão me ajudando muito a me desenvolver 🚀
@MarksmanVallecillo
@MarksmanVallecillo 7 ай бұрын
Thanks, man very good video. 10 Stars ⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
@suvakshaacharya6900
@suvakshaacharya6900 2 ай бұрын
thanks . helped a lot
@nabilachehlafekir8577
@nabilachehlafekir8577 7 ай бұрын
thank you
@jouebien
@jouebien 6 күн бұрын
grouse wrapping the context in a hook. You can build up the provider with state & mutators and pass that to the value of the provider. There's no need to wrap the context with hook jank to extend the context -> with a wrapped hook A) you're not enforce access & mutations B) you also have an extra shit tonne of renders as the hook runs through state changes in every component C) you remove the useContext which hides the fact the component is consuming global/shared state.
@juststudying1019
@juststudying1019 3 ай бұрын
Amazing channel, thanks.
@nogafouz2174
@nogafouz2174 4 ай бұрын
realy thank you but i have a question please which better using context api or redux tookit
@codehustler8582
@codehustler8582 2 ай бұрын
Amazing Channel for Learning React
@safareesamuels4674
@safareesamuels4674 5 ай бұрын
Home of React well explained Tutorials
@user-wq9xz9yc7c
@user-wq9xz9yc7c 5 ай бұрын
I speak another language, but I'm happy to find this video. Thanks!
@cosdensolutions
@cosdensolutions 5 ай бұрын
Working on adding translated captions to all videos soon!
@PravinsPhotos
@PravinsPhotos 3 ай бұрын
I really did subscribe at 1:57...good one there😂
@Bilo_7
@Bilo_7 9 ай бұрын
I made an instant subscription 👍
@cosdensolutions
@cosdensolutions 9 ай бұрын
🤙
@abdoseadaa
@abdoseadaa 3 ай бұрын
i put like b4 watching your videos :) legend
@shekhtausif2811
@shekhtausif2811 11 ай бұрын
Just make more videos like this on react plz you explain really well
@cosdensolutions
@cosdensolutions 11 ай бұрын
Will do!
@mark-broomfield
@mark-broomfield 5 ай бұрын
Great tutorial thanks. My subwoofer got a serious workout every time you banged the mic though :-)
@cosdensolutions
@cosdensolutions 5 ай бұрын
LOL 😂 it gets better in later videos I promise!!!
@fun2rideadventure
@fun2rideadventure 9 ай бұрын
... done ... subscribed :) !!!
@ask43242flight
@ask43242flight 8 ай бұрын
The code in video only handles either normal or undefined cases. Is it true that we don't need to handle the null case?
@cosdensolutions
@cosdensolutions 8 ай бұрын
in this case you don't, because you define your context as `undefined` initially, then it gets set to a value. So it will be either value or undefined, never null
@Atomatiz
@Atomatiz 4 ай бұрын
Cosden. I love you bros 😉
@shubhamshekhar23
@shubhamshekhar23 4 ай бұрын
Hi Cosden, Can you please also explain how does changing variable in a Context can cause rendering of the whole tree inside. I had created a global conttext and provided in the root of the App. Now, A deeply nested component changes the var in this context but I can see that the whole app is getting rendered (but that deeply nested component consuming that context should rerender right?) Any help and clarification is much appreciated. Thanks 🥸
@deepakkashyap6538
@deepakkashyap6538 7 ай бұрын
I have a question in my mind, which is what would happen if a developer uses this custom hook above the provider component i.e a component which is not a child of the provider , how to add exception or error message?
@cosdensolutions
@cosdensolutions 7 ай бұрын
I talk about this in the video! Rewatch it and pay attention!
@brunopagno
@brunopagno 6 ай бұрын
Nice video!
@abdulbasir8740
@abdulbasir8740 4 ай бұрын
Hey, thank you! are you using VIM?
@user-lg2xl1ik9k
@user-lg2xl1ik9k 2 ай бұрын
The best video about useContext! Your explanation is super clear and easy to follow, thank you so much! And, I found your import seems to have an alias like @page/../../../dashboard.tsx. Can you make a video to share how to set it up? I've been looking for how to setup path alias in React for a long time.
@cosdensolutions
@cosdensolutions 2 ай бұрын
I have a short on it actually!
@satadhi
@satadhi 6 ай бұрын
Great explaination ! If I may ask can I get the github link or the code used for the example. Thanks a lot
@cosdensolutions
@cosdensolutions 5 ай бұрын
it's in the description!
@gentlemanjack4083
@gentlemanjack4083 2 ай бұрын
I have a question. in line 8 of context.ts file we are having user = useContext(DashboardContext). How exactly this works behind the scenes that in this place we are able to get actually the user value passed in the Dashboard.Provider ?
@cosdensolutions
@cosdensolutions 2 ай бұрын
yes that's exactly it!
@24pratikbhagwat68
@24pratikbhagwat68 7 ай бұрын
Hey bro what's ur theme name of vs code it looks very warm for eys please tell the name and the video was really great
@cosdensolutions
@cosdensolutions 7 ай бұрын
material theme darker
@felippenvieira
@felippenvieira 4 ай бұрын
Cosden, for example, if we are using JWT authentication, could this approach be replaced by Server Action? I mean, I have a middleware checking if some route is being used. If it's being used, it will check if the user is logged in by reading the authentication cookie. If the answer is no, the middleware will redirect the user to the login page, otherwise it will allow the user to access the route. Also, the server action will do the job of caching the authentication, and we can have access to the user action. With this approach, can we get ride of the useContext?
@cosdensolutions
@cosdensolutions 4 ай бұрын
yeah in that case you could!
@sumitmondal7717
@sumitmondal7717 7 ай бұрын
what theme you use in vs code please reply
@cosdensolutions
@cosdensolutions 7 ай бұрын
material theme darker
Learn React Hooks: useRef - Simply Explained!
12:42
Cosden Solutions
Рет қаралды 71 М.
Context API in react | get the concept
29:00
Hitesh Choudhary
Рет қаралды 35 М.
McDonald’s MCNUGGET PURSE?! #shorts
00:11
Lauren Godwin
Рет қаралды 33 МЛН
The magical amulet of the cross! #clown #小丑 #shorts
00:54
好人小丑
Рет қаралды 17 МЛН
You Are Using useEffect Wrong
14:40
Cosden Solutions
Рет қаралды 28 М.
How To Type Children In React? JSX.Element vs ReactNode
3:30
Oskar Puchalski
Рет қаралды 1,4 М.
Context API Tutorial For Beginners - Using React Hooks
12:26
PedroTech
Рет қаралды 187 М.
Learn React Hooks: useReducer - Simply Explained!
13:48
Cosden Solutions
Рет қаралды 40 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
You Need React Query Now More Than Ever
11:04
Theo - t3․gg
Рет қаралды 135 М.
React useContext() hook introduction 🧗‍♂️
11:37
Bro Code
Рет қаралды 12 М.
You might not need useEffect() ...
21:45
Academind
Рет қаралды 131 М.
Redux - Complete Tutorial (with Redux Toolkit)
37:01
Cosden Solutions
Рет қаралды 134 М.