React Hooks Tutorial - 22 - useReducer with useContext

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ต.ค. 2024
  • 📘 Courses - learn.codevolu...
    💖 Support UPI - support.codevo...
    💖 Support PayPal - www.paypal.me/...
    💾 Github - github.com/gop...
    📱 Follow Codevolution
    Twitter - / codevolutionweb
    Facebook - / codevolutionweb
    📫 Business - codevolution.business@gmail.com
    useReducer with useContext in React

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

  • @porter2k7
    @porter2k7 5 ปีที่แล้ว +61

    Hey dude, I just wanted to say how much you have helped me throughout my studies of react hooks. It's awesome that someone is producing high quality educational content. Thank you very much!

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

    11:44
    You can destructuring object
    for example
    const {countState, countDispatch} = useContext(CountContext)
    then directly use 'countDispatch' instead of using : countContext.countDispatch!
    it's more cleaner.
    thank u bro

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

      Thank you :)

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

      const [ count, dispatch ] = useContext(CountContext); :)

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

      @@imharishsambasivam I dont think it useContext returns an array, you have to destructure using obj only

  • @LuizAzevedown
    @LuizAzevedown 5 ปีที่แล้ว +71

    Congratulations on your playlist. Expanded my knowledge in hooks. I would like to see more examples of useReducer and useContext in a more complex way. Of course if possible. thanks.

  • @ARQAlejandroM
    @ARQAlejandroM 5 ปีที่แล้ว +12

    The way you explain and the methodology, everything is sooo good. Amazing!

  • @babycheesus666
    @babycheesus666 4 ปีที่แล้ว +10

    dude, you are the best. Ive struggled to understand some of these concepts for a long time and you've helped me inmensely with this playlist. Thank you so much

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

    bro thank you for helping me understand useReducer. you are a 100% teacher. I wish I could learn from you in person. No matter what I will never give up, and learn this field. I hope I meet you one dat. Thank You brother

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

    Thank you so much ...I just started my career in web devlopment and i have trouble in understanding react hooks ... Your series helps me a lot .. Thank you so much for your knowledge

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

    No other course or channel helped me on understanding some React concepts like your channel did. Thank you, brother!

  • @amabenuzoe250
    @amabenuzoe250 4 ปีที่แล้ว +5

    Codevolution, you are a great teacher. I've understood the Hooks concept perfectly. My only problem with React is that little projects take up lots of coding. I appreciate your channel. Kindly do a tutorial on how to connect React with a Backend. Thanks once again.

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

      for small projects better to just avoid frameworks altogether in my experience

  • @BharatSingh-zk8lx
    @BharatSingh-zk8lx 4 ปีที่แล้ว +3

    I am watching ur vids since 2019. And I feel u r wayyy much better than those online paid courses. Thanks a lot. And I wish u continue contributing like this forever. Will surely contribute towards you. Hats off

  • @HimanshuPrajapati-p4h
    @HimanshuPrajapati-p4h ปีที่แล้ว

    Vishwas sir you don't know how much you are helping developer to understand react. This hooks playlist is just amazing amazing amazing amazing and is the best react hooks playlist I have ever seen. Thank you so much❤

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

    This is the way to teach a very complex topic ... I've seen others, this is by far the BEST!! THANK YOU VERY MUCH ... Plz keep ém coming ...

  • @piyushaggarwal5207
    @piyushaggarwal5207 2 ปีที่แล้ว

    i think you might be the best i have seen who explains things well and in detail

  • @NeerajKumar-nr6bl
    @NeerajKumar-nr6bl 4 ปีที่แล้ว +1

    The first tutorial about making state global using hooks which so so easy to understand, even I don't need to watch it again, so thanks a lot.. You're amazing and please keep making videos on hooks with same way..

  • @Virus-ke8xj
    @Virus-ke8xj 4 ปีที่แล้ว +4

    Thanks a lot! I haven't gone through redux, but this looks cleaner and nicer!
    Instead of wrapping the whole App component, it would have been better if u would have wrapped only required components 😁
    Thanks to the crystal clear explanation😊😊😊🙏❤️❤️❤️

  • @DexterrrrX
    @DexterrrrX 2 ปีที่แล้ว

    Thank you so much…simple examples to clearly get the steps and easily get the picture. Thank you so so much.

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

    1:28 components might need to share the same counter, the straightforward solution is to declare the counter at highest level and pass it down through props to components but if nested then this will be prop drilling
    Using context hook with reducers allows nested components to use state without drilling

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

    Straight, Simple & To-the-point !!! Thanks for the awesome tutorial :)

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

    thank you very much bro i was struggling with your topic so much but after i saw your video everything got cleared

  • @alwaysjafar
    @alwaysjafar 3 ปีที่แล้ว

    Pretty much clear about the shopping cart concept... thanks a lot team "Codevolution"

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

    This is a very god tier tutorial and explanation. Good work dude, you have good pedagogical skills!

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

    Awesome video!! Very clean and superb explanation! I'm really glad to watch your React.js videos! Thanks.

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

    Hey! I reached so far and wanted to say thank you for your time and explaining! Helps a lot!

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

    This is different level of teaching . Thank you a lot ...

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

    Man even Thanks you feels very tiny for ur work Hatsoff man Seriosuly Ur helping my work and life easy 💓

  • @jpchennai
    @jpchennai 4 ปีที่แล้ว +33

    Note: useReducer + useContext = Redux

    • @oussamakhalfi1751
      @oussamakhalfi1751 4 ปีที่แล้ว +4

      and x100 times cleaner

    • @cabdifataaxcabdilaahi124
      @cabdifataaxcabdilaahi124 3 ปีที่แล้ว

      are you sure??

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

      useReducer + useContext = small redux.-----------|
      |---->Flux is the father
      useSelector + useDispatch = Redux. -----------|
      XDD
      Regards

    • @WeAreTeamNovus
      @WeAreTeamNovus 3 ปีที่แล้ว

      @@oussamakhalfi1751 Redux cleaner or useReducer + useContext?

    • @pjguitar15
      @pjguitar15 3 ปีที่แล้ว

      Which is better?

  • @kirankumarahir7933
    @kirankumarahir7933 3 ปีที่แล้ว

    Pro level explanation! Can't get better than this!!!

  • @ddh97
    @ddh97 3 ปีที่แล้ว

    You deserve million views, I learned a lot from these videos

  • @bhrajgopal
    @bhrajgopal 3 ปีที่แล้ว

    Wow your videos are great to watch . The way you are explaining concepts is really fantastic . Nice knowledge transition .

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

    Understood completyly thank you vishwas sirrr

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

    Amazing! Really good explanation.

  • @anonymouspersin
    @anonymouspersin 4 ปีที่แล้ว

    Awesome bro! You explained this concept really well. Thanks a lot Vishwas

  • @piyushaggarwal5207
    @piyushaggarwal5207 2 ปีที่แล้ว

    I got my answer in the first lines you said. Thanks

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

    Hats off sir Allah bless you.

  • @oluteax8689
    @oluteax8689 4 ปีที่แล้ว

    This is the best so far.

  • @logistics_guy
    @logistics_guy 3 ปีที่แล้ว

    Excellent series! Easy to follow.

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

    Too good and too simple 😊

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

    Next level explanation.

  • @hectorg362
    @hectorg362 2 ปีที่แล้ว

    Soooooo simple! Thanks for this!

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

    simple & efective, thanks

  • @bkipropkibet
    @bkipropkibet 5 ปีที่แล้ว

    You deserve a million views and stars
    am better than ever

  • @snake1625b
    @snake1625b 3 ปีที่แล้ว

    10/10 explanation

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

    This replaces the entire redux concept !!! in such a simple way..

  • @psyferinc.3573
    @psyferinc.3573 ปีที่แล้ว

    you helped me as well. thank you .

  • @patricio758
    @patricio758 4 ปีที่แล้ว

    man you are good at teaching ! , subscribed

  • @mr.RAND5584
    @mr.RAND5584 4 ปีที่แล้ว +1

    Thanks for this tutorial. I want to pass generated token for each component and it will be save to sessionstorage.

  • @somyasingh3551
    @somyasingh3551 2 ปีที่แล้ว

    Damn!! This video is so helpful. Thanks man..

  • @MuhammadAhmed-wb2sq
    @MuhammadAhmed-wb2sq 2 ปีที่แล้ว

    Thanks for those videos.

  • @binc8925
    @binc8925 3 ปีที่แล้ว

    Excellent tutorial, thank you!

  • @muhammadibad7155
    @muhammadibad7155 4 ปีที่แล้ว

    Love the way you explain :)

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

    This concept works even if we implement it by using useState and useContext Hooks.. Can I know what Is the exact difference between using useState and useReducer in this concept

  • @dxxta
    @dxxta 4 ปีที่แล้ว

    thnks for the explanations :) very simple and helps me a lot

  • @sharonfrancis663
    @sharonfrancis663 2 ปีที่แล้ว

    Thank you Brother🙏

  • @crazyshala4571
    @crazyshala4571 4 ปีที่แล้ว

    Great tutor with great knowledge

  • @Action1246
    @Action1246 4 ปีที่แล้ว

    I was searching the material on internet regarding the data communication child to parent, I got so many but did't get concept from there.
    Now I got it from here. But still some query is there if we are writing context. Provider without defining in parent how we will wrap and send data from child to parent.
    Thanks you very much Sir... 👍

  • @owltrades
    @owltrades 3 ปีที่แล้ว

    This is Magic bro

  • @RoyBoyLab
    @RoyBoyLab 2 ปีที่แล้ว

    Awesome video !

  • @Bladefield
    @Bladefield 3 ปีที่แล้ว

    You guys need to pay attention to the re-render of the children component if we do this way :)

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

    For some reasons I’m getting an “Error: Element type is invalid: expected a string (for built- in components) or as a class/function (for composite components) but got: object . You likely forgot to export your component from the file it’s defined in, or you might have mixed up default and named imports.

  • @hamzajamal2047
    @hamzajamal2047 5 ปีที่แล้ว

    you deserve million views

  • @l.n.v.adityavadri8639
    @l.n.v.adityavadri8639 5 ปีที่แล้ว +2

    Thank you Codevolution for explaining React.js in an amazing way, and sharing them online
    could you also make videos on Reactstrap too...

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

    Hi I implemented the same code, but I am getting a error that I cannot read countState even though it is in a higher level?

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

    What Did I learn from this EP22
    to access global variables or values which is passes using useContext hook in it's child components
    useReducer + useContext

  • @IvanFedulov
    @IvanFedulov 5 ปีที่แล้ว +18

    this is how we cat get rid of redux and use all the stuff from react :)

    • @zealousprogrammer4539
      @zealousprogrammer4539 4 ปีที่แล้ว +9

      Yes I understand some react stuff but to me Redux is like Korean mixed with Thai impossible to understand! :)

    • @BharatSingh-zk8lx
      @BharatSingh-zk8lx 4 ปีที่แล้ว +1

      @@zealousprogrammer4539 hahaha, EPIC HAHAHA, but actually its not that complex.

    • @Virus-ke8xj
      @Virus-ke8xj 4 ปีที่แล้ว

      @@BharatSingh-zk8lx bro, I have properly understood useReducer and useContext, do I have to learn redux still?

    • @BharatSingh-zk8lx
      @BharatSingh-zk8lx 4 ปีที่แล้ว +2

      @@Virus-ke8xj yes coz context is not suitable for large scale apps. Redux is much preferred in that case. U should do some research redux over context 👍

  • @baseljuma158
    @baseljuma158 5 ปีที่แล้ว

    Thank you again ... an waiting for the next video :)

  • @voldemort576
    @voldemort576 3 ปีที่แล้ว

    mazza aa gaya

  • @aqkhana2002
    @aqkhana2002 3 ปีที่แล้ว

    Viswah you are GR8 Teacher , do you have these courses in UDEMY or any where ?

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

    Very useful

  • @ujolmaharjan2010
    @ujolmaharjan2010 2 ปีที่แล้ว

    brilliant ur great.

  • @linsin8166
    @linsin8166 3 ปีที่แล้ว

    Thanks My teacher

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

    not sure if it is me only or others also wonder about few features like useState, useReducer & useContext. Means if we need to share the state & behavior with other components then why cant I create a class object having the state & behavior & import it where-ever required like doing with use*() features.

  • @golansy2814
    @golansy2814 2 ปีที่แล้ว

    a lot of thanks

  • @johnattantibocha2981
    @johnattantibocha2981 3 ปีที่แล้ว

    its the same concept of Redux, only the different is that you can create many useContext as you want, in redux only one global and you create the reducers as you want.
    The main question. Is it accept async calls?

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

    Hello there I am using vite and every time I save the App.js it result in blank page and throw an error says: Uncaught TypeError: Cannot read properties of undefined (reading 'countState')

  • @toannew
    @toannew 3 ปีที่แล้ว

    thank you so so much.

  • @richard_keep
    @richard_keep 3 ปีที่แล้ว

    Great videos. I giggle when you pronounce the name "Provider". You make it sound like "Prowaida"... or maybe it's my ears. :)

  • @ibealgoody8524
    @ibealgoody8524 3 ปีที่แล้ว

    Is it really good practice to have your reducers in app.js?

  • @_jovian
    @_jovian 2 ปีที่แล้ว

    question for anyone who knows the answer- why is he wrapping app.js's return in a provider rather than defining a value in the createContext declaration and then using useContext?

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

    i have 3 components but only one state...now i need to change the value of the state. for each component it should maintain separate value. how can we implement it??

    • @saik1428
      @saik1428 4 ปีที่แล้ว

      create seperate local states

  • @vladimirh.5934
    @vladimirh.5934 ปีที่แล้ว +1

    Is it also possible to use useState with useContext to manage global state? And if not, why? Thank you for your reply :)

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

      Yes, Possible wastch Piyush Garg Context Api video , You will understand that completely

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

    Great video.
    Can this technique scale for medium/large scale applications?
    I have been using redux for some time and this method seems like a less painful way of doing so but I feel like there is a catch I might be missing. your thoughts?

  • @raidertm1653
    @raidertm1653 2 ปีที่แล้ว

    Very well

  • @jagdishshetty4782
    @jagdishshetty4782 5 ปีที่แล้ว

    Great tutorial !!!

  • @VishalSharma-rn7mt
    @VishalSharma-rn7mt 3 ปีที่แล้ว

    Awesome

  • @doncamill
    @doncamill 2 ปีที่แล้ว

    No errors but every time i click on count it just count +1 and reset its state to initial state ..

  • @NITESHSINGHNRS
    @NITESHSINGHNRS 4 ปีที่แล้ว

    best like always

  • @rajnandanibhawsar3105
    @rajnandanibhawsar3105 2 ปีที่แล้ว

    you are awesome :)

  • @TThiele
    @TThiele 3 ปีที่แล้ว

    What if one of the Childres inside a Provider is a Class?
    Is there any possibility to transfer values then? because i know, that Hooks are NOT possible in Classes ...

  • @aadil4236
    @aadil4236 3 ปีที่แล้ว

    What if I wanted to make some changes to component A if some event occurs in component B? I tried to use the traditional way of doing that as you showed in the video but component A doesn't update if an event occurs in components B. only component A re-renders in this case. so I have to pass the global state and dispatch function from the app to all the component. If you know a solution where I don't have to pass the global state and dispatch function from the app component that would be very helpful.
    Thank you.

  • @gokulg2756
    @gokulg2756 3 ปีที่แล้ว

    Asam💥💥💥

  • @simple8810
    @simple8810 3 ปีที่แล้ว

    As I noticed clicking the ParentComponent Button it also effect the child component(whre we consumer contextAPI) ,is there any way to solve this,Means I want one compoenent donot change the counter value in other ?

  • @mayadajacob1182
    @mayadajacob1182 2 ปีที่แล้ว

    perfect

  • @Vihansh0810
    @Vihansh0810 4 ปีที่แล้ว

    What is the Major difference between useContext and Redux ? and if kill the app, useContext data will store or killed when again open the App?

  • @iiit5
    @iiit5 4 ปีที่แล้ว

    Really Good!!!!

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

    We don't need consumer with context here? Or am i missing something.

    • @murali-krishnan
      @murali-krishnan ปีที่แล้ว

      Yeah, we don't need consumers that's why we are using useContext hook to consume it. I would recommend you to watch useContext hook video 15-17

  • @kamrangondal9009
    @kamrangondal9009 2 ปีที่แล้ว

    😍

  • @maheerali531
    @maheerali531 4 ปีที่แล้ว

    We are using the same code in three components. Is there a way to get rid of repetition

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

      Take Component F as the lowerst level of the component that is responsible for providing the buttons. Then in Component A and D, replace the code for the buttons with just Component F. E.g.
      function ReducerContextComponentD() {
      const countContext = useContext(CountContext)

      return (

      Component D Count: {countContext.countState}

      )
      }

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

    My state does not update immediately. Why is that and how can it be fixed?

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

      are you using a useState or useReducer? consider useEffect and the dependencies

  • @sagar_pawar27
    @sagar_pawar27 4 ปีที่แล้ว

    @Codevolution when we use initialState as an object it gives an error how can we handle it?

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

      Share your code so people can help

  • @numanmazhar-0206
    @numanmazhar-0206 3 ปีที่แล้ว

    TypeError: Cannot read property 'count dispatch' of undefined
    when a click on buttons any solution

    • @joannamollman8165
      @joannamollman8165 2 ปีที่แล้ว

      I had the same. In component A I did not import CountContex as a named component {CountContex}. Hope that helps