Learn React Hooks: useContext - Simply Explained!

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ย. 2024
  • 🚀 Project React → cosden.solutio...
    📥 Import React (Newsletter) → cosden.solutio...
    Join The Discord! → discord.cosden...
    Source Code → github.com/cos...
    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!

ความคิดเห็น • 289

  • @cosdensolutions
    @cosdensolutions  6 หลายเดือนก่อน +8

    Hope you enjoyed the video! I also have a really cool and unique course that will teach you way more than this video. You'll learn how to build an actual complex project with React. It's called "Project React" and you can find it at cosden.solutions/project-react. Also, I have a free weekly newsletter called "Import React" with tutorials, news, and cool stuff about React! You can sign up at cosden.solutions/newsletter?s=ytc

  • @mikoajkulczynski5213
    @mikoajkulczynski5213 11 หลายเดือนก่อน +27

    Thank you for the content. You have the gift to talk about coding in a simple way.

    • @cosdensolutions
      @cosdensolutions  11 หลายเดือนก่อน

      thank you for the kind words!

  • @David-eb8lh
    @David-eb8lh หลายเดือนก่อน +3

    Clear explanations with no "fluff!

  • @shubhankarvalimbe5286
    @shubhankarvalimbe5286 11 หลายเดือนก่อน +24

    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  11 หลายเดือนก่อน +2

      makes me happy to hear!

  • @prshendra
    @prshendra 9 วันที่ผ่านมา

    It's like eating a tasty food for the brain. Your presentation and words used is really easy to understand and not verbose. Liked and subscribed.

  • @HR-pz7ts
    @HR-pz7ts 7 หลายเดือนก่อน +7

    It's amazing you also taught how to deal with problems and showed proper way to code and handle potential errors.

  • @omobolanleayobami4998
    @omobolanleayobami4998 2 หลายเดือนก่อน +1

    I have seen a lot of videos on context but this is the best. easy to understand and follow through. thank you.

  • @GeraldPajulas
    @GeraldPajulas 8 หลายเดือนก่อน +8

    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.

    • @khairulfahim-j9o
      @khairulfahim-j9o หลายเดือนก่อน

      did you complete your react journey?

  • @camilotorresf1
    @camilotorresf1 ปีที่แล้ว +25

    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  ปีที่แล้ว +1

      Really happy to hear that dude! You're going to do great ☺️ thank you for the kind words!

    • @reallegendcode
      @reallegendcode 9 หลายเดือนก่อน

      @@cosdensolutions please when are going to do a video on HOC

  • @osmankain1508
    @osmankain1508 6 หลายเดือนก่อน +4

    Wow you're a perfect teacher and programmer thanks for the time that you spent for this amazing content

  • @yongdiamond2301
    @yongdiamond2301 10 วันที่ผ่านมา

    Thanks for content it get me out of props drilling and gaining to know the power of the useContext and customHook.

  • @seelvek6550
    @seelvek6550 14 วันที่ผ่านมา

    Great explanation! I am new to React and your Hook series are really helpful to me. As I also do not have much time to go over everything and this is clear, on point and very concise. Thank you 🙇

  • @michaelkroll6913
    @michaelkroll6913 9 วันที่ผ่านมา

    Thank you very much for your video. I finally cleaned up my context implementation and were able to get rid of the question marks 🙂

  • @marshallfungai3033
    @marshallfungai3033 9 หลายเดือนก่อน +3

    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.

  • @shawn.builds
    @shawn.builds 5 หลายเดือนก่อน

    been loving the react tutorials man! dont think anyones ever explained context so simply :)

  • @AntNZ
    @AntNZ ปีที่แล้ว +11

    Wow! Such a excellent explanation and with examples too. Well done 👏👏👏👏

  • @prabhanshugupta9361
    @prabhanshugupta9361 21 วันที่ผ่านมา

    I watched you before because I have already subscribed some of coding channels but I watched your single video with all of my focus and then I did a subscribe to a channel which was your channel and started watching another video from your channel... Thank You !

  • @jay-kv6wn
    @jay-kv6wn ปีที่แล้ว +6

    I hope your videos go viral soon like they should. You are doing a great work with your explanations

    • @cosdensolutions
      @cosdensolutions  ปีที่แล้ว

      Haha imagine going viral for React 😅 would love it!

  • @_romeopeter
    @_romeopeter 4 หลายเดือนก่อน

    This was straight forward. Thank you for throwing in the extra error handling method as well 🔥

  • @YisneySoto
    @YisneySoto ปีที่แล้ว +2

    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.

  • @Caiocsilveira
    @Caiocsilveira หลายเดือนก่อน

    1:34 that was genious and I subd immediately. Nice work!

  • @mostinho7
    @mostinho7 3 หลายเดือนก่อน +1

    Done thanks!
    Wrap useContext hook in a custom hook to handle when the context is null (if component didn't have provider up in the tree when it should have and tried to use the context hook)

  • @user-gm3lg8gp3m
    @user-gm3lg8gp3m ปีที่แล้ว +3

    I subscribed!! This is a great way to explain the concept + thanks for adding the error handling part 👍

  • @mchisolm0
    @mchisolm0 5 หลายเดือนก่อน

    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.

  • @fg0611
    @fg0611 3 หลายเดือนก่อน

    Bro thank you for this video! amazing. I have an interview in 1 hour and it's main thing is knowing about react context!

  • @franbrankovic3617
    @franbrankovic3617 ปีที่แล้ว

    After this video you really don't need to watch another video about react useContext. This was excellent video.

  • @sub_in01
    @sub_in01 ปีที่แล้ว +1

    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.

  • @Елена-б6в3ж
    @Елена-б6в3ж หลายเดือนก่อน

    Thank you! It's so clear

  • @reallegendcode
    @reallegendcode 10 หลายเดือนก่อน

    Top-notch explanation. Manifesting 100k subscribers by end of this year

  • @Chris-by8tg
    @Chris-by8tg 8 หลายเดือนก่อน

    This was the clearest explanation I've seen. Thank you!

  • @theppiwatkomolwat4429
    @theppiwatkomolwat4429 10 หลายเดือนก่อน

    1:31 This part of the code worked; I have now subscribed!

  • @AhmedHuzain
    @AhmedHuzain 9 หลายเดือนก่อน

    "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!

  • @jijocleetus
    @jijocleetus 8 หลายเดือนก่อน

    Great one with context, i like the way you handled the undefined scenario. Thanks for the tutorial.

  • @thebeastsclips
    @thebeastsclips 9 หลายเดือนก่อน +3

    useContext is a great alternative for a bunch of prop drilling with a bunch of useStates as well in the child component as well.

  • @calmmind3160
    @calmmind3160 หลายเดือนก่อน

    you know im a sub bro, your videos is my goto for react content- one day inshallah i meet you when i build an insane app

  • @jeandedieuiradukunda6079
    @jeandedieuiradukunda6079 2 หลายเดือนก่อน

    that's incredibly explained, thank you sir

  • @Aiexpertise-ft9ec
    @Aiexpertise-ft9ec 3 หลายเดือนก่อน

    I grabs those points clearly, thanks dude.

  • @brNoMundo123
    @brNoMundo123 7 หลายเดือนก่อน

    Sou desenvolvedora Júnior e seus vídeos estão me ajudando muito a me desenvolver 🚀

  • @mgx49
    @mgx49 6 หลายเดือนก่อน

    No doubt I won't need to watch another React Context API video! [Subscribed]

  • @rmc1579
    @rmc1579 9 หลายเดือนก่อน

    great explanation. I was a little bit confuse when using context and how to implement them.

  • @antoninosartori
    @antoninosartori 10 หลายเดือนก่อน +2

    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 9 หลายเดือนก่อน

      If user come from server state, don't throw error in custom hook, just return user.

  • @Jack-ps4jg
    @Jack-ps4jg 3 หลายเดือนก่อน

    really nice and simple explanation thank you for making this video

  • @vampirekabir
    @vampirekabir ปีที่แล้ว

    trying to get a grasp of it,nobody taught like u did,i finally get it now ❤❤

  • @MessiLeo2312
    @MessiLeo2312 7 หลายเดือนก่อน

    man, awosome video crystel clear concepts and learned how to write a more safe code(in the pov for debugging)

  • @HerlonCosta
    @HerlonCosta 10 หลายเดือนก่อน

    I reall like this explanation. You're very good, god bless you!

  • @glenmccallum7051
    @glenmccallum7051 ปีที่แล้ว +1

    Thanks a lot, this was really helpful. Really great video and great channel

  • @syedayanata9765
    @syedayanata9765 ปีที่แล้ว

    I watched many videos and still did not understand context but this video helped me a lot.

  • @НатальяКостоломова-ъ5г
    @НатальяКостоломова-ъ5г 10 หลายเดือนก่อน

    I speak another language, but I'm happy to find this video. Thanks!

    • @cosdensolutions
      @cosdensolutions  10 หลายเดือนก่อน

      Working on adding translated captions to all videos soon!

  • @Amarichezineddine
    @Amarichezineddine 9 หลายเดือนก่อน +1

    Thanks it was very helpful

  • @theGameThrough
    @theGameThrough ปีที่แล้ว +3

    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

  • @myothiha1168
    @myothiha1168 ปีที่แล้ว +1

    best explanation ever!🤩

  • @shekhtausif2811
    @shekhtausif2811 ปีที่แล้ว +2

    Just make more videos like this on react plz you explain really well

  • @tokaqarcivadze5825
    @tokaqarcivadze5825 11 หลายเดือนก่อน

    the way you explain react is the best!

  • @inspacesilence
    @inspacesilence 3 หลายเดือนก่อน

    1:37 if you really want user to get you subscribed create content which user want to watch again and again, most of us won't subscribe but still hit a like button just because we know this video is great and we can come back to you by searching you, to be in our feed create something which we want to see on daily basis and these things are not one watches on daily basis... this is just a advice... you gained 1 subscriber

  • @ooorayooonyoooo
    @ooorayooonyoooo ปีที่แล้ว

    A really underrated channel, well done bro! ⚡❤

  • @nogafouz2174
    @nogafouz2174 9 หลายเดือนก่อน +1

    realy thank you but i have a question please which better using context api or redux tookit

  • @RyS29
    @RyS29 10 หลายเดือนก่อน +1

    Great content, thank you!

  • @poornasaipilla1620
    @poornasaipilla1620 7 หลายเดือนก่อน

    Really use full video thanks for doing ... extending my great full and encouragement .... keep doing well..

  • @jouebien
    @jouebien 4 หลายเดือนก่อน

    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.

  • @Namishkapoor-u4m
    @Namishkapoor-u4m 6 หลายเดือนก่อน

    I literally subscribed after seeing your message in the Video

  • @Temefaa
    @Temefaa 2 หลายเดือนก่อน

    Great tutorial thanks !

  • @moppnitz
    @moppnitz 3 หลายเดือนก่อน

    man.. this is a lot to wrap my head around

    • @DevMeloy
      @DevMeloy หลายเดือนก่อน +1

      With a few exceptions, I'd stay away from context. It sounds like an easier way to share state but come with some significant performance penalties on larger apps.

  • @mboe94
    @mboe94 9 หลายเดือนก่อน

    That subscribe intro you did made me subscribe. Genius.

  • @admasterefe4340
    @admasterefe4340 5 หลายเดือนก่อน +1

    GOD level explanation. I want everyone to subscribe to this channel. Too bad one can't give two likes.

  • @simplebutcorrect6176
    @simplebutcorrect6176 11 หลายเดือนก่อน

    Bro I love the way that you explain keep it up. Subscribed❤

  • @陳子雋-v6i
    @陳子雋-v6i 3 หลายเดือนก่อน

    thanks man I really understood it. Subscribed already

  • @atifasadkhan
    @atifasadkhan 28 วันที่ผ่านมา

    Thankyou very much!

  • @sudiptobose8296
    @sudiptobose8296 6 หลายเดือนก่อน

    Fantastic tutorial. I really appreciate it. 😊

  • @marceloleoncaceres6826
    @marceloleoncaceres6826 8 หลายเดือนก่อน

    Great video, thanks for sharing your time and knowledge,

  • @codehustler8582
    @codehustler8582 6 หลายเดือนก่อน

    Amazing Channel for Learning React

  • @cypherop2608
    @cypherop2608 9 หลายเดือนก่อน

    you made it soooooo easy to understand

  • @PravinsPhotos
    @PravinsPhotos 8 หลายเดือนก่อน

    I really did subscribe at 1:57...good one there😂

  • @safareesamuels4674
    @safareesamuels4674 10 หลายเดือนก่อน

    Home of React well explained Tutorials

  • @shivasai7707
    @shivasai7707 4 หลายเดือนก่อน

    great explaination on useContext

  • @niconel7659
    @niconel7659 11 หลายเดือนก่อน

    Thanks for the reminder to subscribe. Guilty as charged, but subscribed now.

  • @anhmap9055
    @anhmap9055 3 หลายเดือนก่อน

    ok lắm anh trai đẹp zai ơi, em mới học mót không học chính thức, ban đầu em đi móc A => B => C => D, bây giờ thì móc A => D )))

  • @mai.krishnahoon
    @mai.krishnahoon 7 หลายเดือนก่อน +1

    Thanks from india..

  • @juststudying1019
    @juststudying1019 8 หลายเดือนก่อน

    Amazing channel, thanks.

  • @CarlosDuque-e3j
    @CarlosDuque-e3j หลายเดือนก่อน

    Good explanation! I have a question: if the user refreshes the page, wouldn't the state stored in the context be lost?

    • @cosdensolutions
      @cosdensolutions  หลายเดือนก่อน

      yeah it would. If you need it, you need to store it in localStorage or db

  • @Andrea-t4j5v
    @Andrea-t4j5v 3 หลายเดือนก่อน

    I didn't understand where it imported the "user" object from, when it creates the context. uswContext is the parent folder? So evereything we're looking at is wrapped inside a chidren of useContext?

  • @antimrevapati8992
    @antimrevapati8992 7 หลายเดือนก่อน

    Great Explanation, Thank you!

  • @awasum
    @awasum 7 หลายเดือนก่อน

    Thank you very much. Good content

  • @drrd5145
    @drrd5145 3 หลายเดือนก่อน

    Nice videos!
    It is possible to change/set Context before going to another screen (using a Link or Pressable component and Expo Router)?
    This example is great to set a value and call a component but not to move to another page,
    I have a JSON object that I receive in the Home page that contains info used by the rest of the App. I want to set the context there and use that info in other pages in the App.
    Thx!

  • @mjylove2
    @mjylove2 3 หลายเดือนก่อน

    great explanation

  • @himago
    @himago 2 หลายเดือนก่อน

    nicee, it works now i'm subscribed

  • @deshannawarathna6283
    @deshannawarathna6283 8 หลายเดือนก่อน

    Thank you man. That is good explanation

  • @abdoseadaa
    @abdoseadaa 8 หลายเดือนก่อน

    i put like b4 watching your videos :)
    legend

  • @abdelhakimkhabir
    @abdelhakimkhabir 3 หลายเดือนก่อน

    don't know why love watching your videos🤍

  • @UnfinishedYara
    @UnfinishedYara 8 หลายเดือนก่อน

    Thanks man! Crystal clear now!

  • @Teddyrobinson
    @Teddyrobinson 7 หลายเดือนก่อน

    Another great tutorial thanks so much!

  • @samahgad241
    @samahgad241 9 หลายเดือนก่อน

    Realy great explanation,thank you

  • @sathirabandara7981
    @sathirabandara7981 8 หลายเดือนก่อน

    Great job man. its very helpful !!

  • @santiagovelezsaffon
    @santiagovelezsaffon 5 หลายเดือนก่อน

    Very well explained !!

  • @yusha790
    @yusha790 4 หลายเดือนก่อน

    You're the best man

  • @vivekkumar-pc1xy
    @vivekkumar-pc1xy 9 หลายเดือนก่อน

    Crystal Clear... Thanks

  • @mark-broomfield
    @mark-broomfield 10 หลายเดือนก่อน

    Great tutorial thanks. My subwoofer got a serious workout every time you banged the mic though :-)

    • @cosdensolutions
      @cosdensolutions  10 หลายเดือนก่อน

      LOL 😂 it gets better in later videos I promise!!!

  • @WelshGuitarDude
    @WelshGuitarDude 5 หลายเดือนก่อน

    How do you change the context value say you want to login as a different username so need to load a dashboard of a different name?

  • @israelkayaba6002
    @israelkayaba6002 9 หลายเดือนก่อน

    Thanks bro, much appreciated !

  • @suvakshaacharya6900
    @suvakshaacharya6900 6 หลายเดือนก่อน

    thanks . helped a lot

  • @MarksmanVallecillo
    @MarksmanVallecillo ปีที่แล้ว

    Thanks, man very good video. 10 Stars ⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐