useReducer is BETTER than useState | React Hook useReducer Tutorial

Поделиться
HTML-код
  • Опубликовано: 26 июн 2024
  • Web Dev Roadmap for Beginners (Free!): bit.ly/DaveGrayWebDevRoadmap
    If you are building React apps with multiple state values to keep track of, your React apps need the useReducer hook! In this useReducer React Hook tutorial, you will learn how to apply useReducer to manage the state of your apps.
    🚩 Subscribe ➜ bit.ly/3nGHmNn
    🚀 React JS for Beginners full course - 9 hours: • React JS Full Course f...
    🔗 Source Code: github.com/gitdagray/usereduc...
    useReducer is BETTER than useState | React Hook useReducer Tutorial
    (00:00) Intro
    (00:12) Welcome and Overview
    (01:05) useReducer vs useState
    (01:53) Initializing useReducer
    (03:33) Creating the reducer function
    (05:42) Using dispatch and updating JSX
    (07:12) Moving all state and handling an action payload
    (08:25) An easy mistake to make
    (10:01) Displaying state values in JSX
    (12:44) Recommended: Action object lookup and dot notation
    🔗 ES7 React JS Snippets Extension for VS Code:
    marketplace.visualstudio.com/...
    🔗 React Dev Tools Extension for Chrome:
    chrome.google.com/webstore/de...
    📚 References:
    ReactJS Official site: reactjs.org/
    React Wikipedia: en.wikipedia.org/wiki/React_(...)
    React Jobs: www.ziprecruiter.com/candidat...
    ✅ Follow Me:
    Twitter: / yesdavidgray
    LinkedIn: / davidagray
    Blog: yesdavidgray.com
    Reddit: / daveoneleven
    Was this tutorial about the React hook useReducer helpful? If so, please share. Let me know your thoughts in the comments.
    #usereducer #react #hooks

Комментарии • 286

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode  2 года назад +36

    The useReducer React hook seems more complicated at first, but after you learn how to use it, useReducer really simplifies state management compared to tracking many different pieces of state that are all implemented with the useState hook. Once you learn about the useReducer hook, I think you will agree! Just getting started with React? If so, I recommend starting with my 9 hour full course React tutorial here: ruclips.net/video/RVFAyFWO4go/видео.html

    • @Tajdev
      @Tajdev Год назад

      You have not demonstrated how to pass it to component. Please also make video of it.

    • @m1dway
      @m1dway Год назад +1

      @@Tajdev just pass it in an input parameter. Ex:

  • @minimumt3n204
    @minimumt3n204 Год назад +20

    Showing how its similar to useState and rewriting it using useReducer makes it so much more clear! Thank you!

  • @jingli9232
    @jingli9232 Год назад +15

    the best tutorial for useReducer, super clear and simple to understand, what a teacher!

  • @andrews13
    @andrews13 Год назад +10

    Tried many tutorials for learning useReducer, but got confused more only. Finally I found this video which is the perfect one!! Simple, great & straight forward!

  • @pablocodeglia
    @pablocodeglia Год назад +19

    What a great and easy-to-get explanation for a pretty confusing topic. Excellent work, thanks Dave!

  • @SagarKumar-db2xy
    @SagarKumar-db2xy 2 года назад +20

    Hands down the best tutorial. I am writing this comment after watching maybe 20+ videos and that too from top youtubers, but no one really simplified this much.
    I just have a request, please make a medium size project using useContext for global state management and useReducer to change them. Pls.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 года назад +5

      Thank you, Sagar! I appreciate the request, too. I do need to post some projects. 🙏💯

  • @maxwellosuji4096
    @maxwellosuji4096 2 года назад +2

    Thank you very much sir. I’ve been having difficulties learning the useReducer hook. I get more confused reading articles and watching other videos. But thankfully You’ve explained and broken down the what, why and usage of this particular hook. I’m so grateful it’s a thumbs up for me👍

  • @try-b2k
    @try-b2k 11 месяцев назад

    I was having problems in learning reducer from a week or so and this video changed evrything, thanx a bunch

  • @purushottamkute7485
    @purushottamkute7485 9 месяцев назад

    I'm literally in tears I watched so many tutorials of useReducer but this one is hands down the best one

  • @Andi-rd8yf
    @Andi-rd8yf 11 месяцев назад

    Exactly what i was looking for, really appreciate your work buddy!

  • @ssj1260
    @ssj1260 Год назад

    It's gotten to the stage where, if i'm unsure about something I just type in "question + Dave Gray" to youtube.
    You have no idea how amazing it is to have a reliable source of information, when I was researching closures I came across so much conflicting information, after your video on them I vowed to make sure I looked at your videos as the main source of truth, they are clean, efficient, well explained and professional.
    Thanks Dave.

  • @El_kammex
    @El_kammex 11 месяцев назад

    Now I Understand more what we need useReducer hook. Great job.

  • @zb2747
    @zb2747 Год назад +2

    Best tutorial and explanation I found - thank you Dave!

  • @javadrip
    @javadrip Год назад

    Watched many useReducer tutorials and this is the best! Simple, easy to follow and no digressing halfway.

  • @arungrg
    @arungrg Год назад +2

    Felt so much like small scale Redux. Loved how you explained everything. Great job 👍

  • @internetdrew
    @internetdrew Год назад +2

    There are a lot of great people teaching these subjects but wow you just made that simple. I just built a fullstack app and most the hold up was micromanaging pieces of state. Going to implement useReducer from here forward.

  • @vincejones3381
    @vincejones3381 10 месяцев назад

    Great example and explanation! I haven’t seen the true value of useReducer until this video and I have been learning React for years.

  • @stokedonthestoke
    @stokedonthestoke Год назад

    Thanks so much! Used this before I attempted to use useReducer in my app and then felt way more confident about what I was going to do. Your vidoes are great, really appreciate it. When I have questions about something I try to find a video from you first!

  • @BrainAido
    @BrainAido Год назад

    Buddy i am probably very late, as i now just started my interest in React ( company switched to some React based CRM ) , i came to thank you X milions for putting together this video, i finally understood state and it ticked in my head as now you gave me a visual representantion in my brain, please accept my thanks i wish you the best.

  • @confusedGuenni
    @confusedGuenni 6 месяцев назад

    I finally got it. Well done tutorial, thank you.

  • @ahmedk4345
    @ahmedk4345 7 месяцев назад

    best explanation i came across, thanx Dave...keep it up!

  • @syeds8314
    @syeds8314 10 месяцев назад

    Many Thanks for the video!❤
    After watching and studying several resources, your video made things clear to me.

  • @xungngo
    @xungngo 10 месяцев назад

    Thanks man, your explanation is superb! Keep up the good work.

  • @4t196
    @4t196 2 года назад +1

    This was easy easy to understand.
    The best useReducer tutorial so far.

  • @SimPwear84
    @SimPwear84 2 года назад

    Nicely explained! Short, sweet and straight to the point. Thank you

  • @ilivetruth
    @ilivetruth 4 месяца назад

    Thank you for the video and explanation, much easier to understand than the docs!

  • @kaioqrz
    @kaioqrz Год назад

    Thank you Dave! After so much time trying to understand the useReducer I finally made it! Thank you man!! :D

  • @joseff5998
    @joseff5998 2 года назад

    Thank you so much Dave! I was really trying to understand the use Reducer. This was so clear!

  • @Un0Real333
    @Un0Real333 2 года назад

    Just brilliant! I did so much refactoring and made my code look better and more reusable, after watching your videos, keep up the good work!

  • @BabaNoami
    @BabaNoami 2 года назад

    Thanks. Very clear explanation. My first real intro to useReducer. Looking forward to putting it into practice.

  • @umairqamar2672
    @umairqamar2672 Год назад

    this is super duper amazing. Thank you Dave

  • @neo90sr
    @neo90sr 2 года назад +1

    Very nice explanation. I had some trouble understanding this, but now it's all clear

  • @felixlutrovnik345
    @felixlutrovnik345 5 месяцев назад

    must admit, i saw at least 5 videos to understand useReducer hook.
    the only one that was fully understandable for me was your video !
    thank you, and keep your great job at explaining fully professional topics for young devs.

  • @AndreeaCozariuc
    @AndreeaCozariuc Год назад

    Dave, you are a blessing. Thank you ❤‍🔥

  • @user-ol6tq5hw7s
    @user-ol6tq5hw7s 2 года назад

    I watched a lot of clips about useReducer and after this it is crystal clear to me so you are great and just keep it up because these are amazing videos and thank you very much for that! Big Greetings from Serbia Dave. :)

  • @hannah51238
    @hannah51238 9 месяцев назад

    This is such a great explanation of useReducer! Thanks very much Dave 😍

  • @jonathanmcgee654
    @jonathanmcgee654 3 месяца назад

    Amazing. I was really lost in why and how to transition from useState to useReducer. Dave walks us through it step by step! Great examples and explanations! Thank you!

  • @barreg17
    @barreg17 Год назад

    I finally understood it. Massive thank you!

  • @dranix5018
    @dranix5018 Год назад

    Very clear and well explained! Thanks.

  • @mtsurov
    @mtsurov Год назад

    Best explanation so far. Appreciate you making this tutorial.

  • @danielconde2729
    @danielconde2729 11 месяцев назад

    Excellent explanation! I was so confused using reducer

  • @focusroom_
    @focusroom_ Год назад

    This is THE BEST tutorial for useReducer, tysm!

  • @adi4057
    @adi4057 Год назад

    The best video to understand this concept. Thank man!!!

  • @randomtalks5253
    @randomtalks5253 Год назад

    You are simply Love!! Such a great video. Helped me alot. Clear toThePoint conCise and compreHensive❤

  • @amancandream
    @amancandream Год назад

    Went through a couple videos about useReducer and was about to give up and go back to Vanilla js lol. But you explained things super well!! Thanks so much! Subbed!

  • @jamshidtashkent1976
    @jamshidtashkent1976 Год назад

    Thank you Dave. It is really cool

  • @JedOpeningThings
    @JedOpeningThings 2 года назад

    Thank you! This is prolly the cleanest and best video for the useReducer hook I can find!

  • @Jawad_Siddiqui
    @Jawad_Siddiqui Год назад

    God gifted teacher😀Thanks

  • @muhammedozalp
    @muhammedozalp 9 месяцев назад

    Thank you bro. This is a very good tutorial.

  • @verydifferentthought
    @verydifferentthought Год назад +1

    I was really having the problem of Redux stuff... But now I can understand where idea of Reducer came from but also dispatch, action and payload which looks like complicated stuff but after your explanation and I got the whole point of the thing. I am grateful of your amazing work from Uzbekistan !

  • @shayanfaghihi
    @shayanfaghihi Год назад

    Wow! You rocked it; Thanks Dave for this super and comprehensive video. I watch the very first second of the video, and I could run the app by myself. The rest was for better understanding 😉

  • @leoMC4384
    @leoMC4384 2 года назад +2

    Great content. I implement useReducer in my project for a form that fetches values from my API to several menus, the user chooses data from the menus and the UI gets updated and the entire form data it's validated at the same time. With useState, it got pretty messy. Now with useReducer it's much better, even though my reducer function got quite long. 😀😀😀

    • @CottidaeSEA
      @CottidaeSEA 2 года назад

      Thankfully the work in your reducer can also be delegated to separate functions.

  • @kamaboko1
    @kamaboko1 2 года назад

    Great video. Subscribed!

  • @fabricio-garcia
    @fabricio-garcia Год назад

    What a great way to teach concepts! Subscribed to the channel already.

  • @ahmad-murery
    @ahmad-murery 2 года назад +1

    This is much more comfortable to work with than using multiple useState hooks as I can manage all my states in one place,
    I thought for a while that we can pass any property when calling dispatch function then in the reducer we can check whatever properties we passed,
    I wasn't sure but after doing some research I found that we should use the type property and optionally the payload property when dispatching an action which makes things more organized,
    sometimes my silliness helps me understand things better,
    Thanks Dave,

  • @iidiez872
    @iidiez872 Год назад

    Best tutorial for useReducer , you made it really easy to understand.

  • @ihateorangecat
    @ihateorangecat Год назад

    this is the video that i learnt useReducer hook and i equipped the knowledge to making a todo app all by useReducer without using useState.
    thanks!🙌

  • @masruralam6199
    @masruralam6199 2 года назад

    How clear explanation, I ever found. Thanks Dave Gray..

  • @gogas2860
    @gogas2860 2 года назад

    Wow, the best explanation of usereducer hook, I've ever watched. Thank you very much!!!

  • @ebesquin
    @ebesquin Год назад

    Thank you so much. As always a great tutorial

  • @TrueSQN
    @TrueSQN Год назад

    I'm from Poland, and for explaining word "dispatch" you have my subscription :D love ya lessons

  • @toppmoviehighlights
    @toppmoviehighlights 2 года назад

    Actually tried the useReducer hook for the first time yesterday..... This has provided a valuable insight to what useReducer really is. Good job.

  • @tomnewton3191
    @tomnewton3191 Год назад

    Great video, very clearly explained.
    Thanks,
    Tom

  • @pfcokelly
    @pfcokelly Год назад

    Subbed, great tutorial!

  • @AvinashSingh-ts1cn
    @AvinashSingh-ts1cn Год назад

    Thanks a ton for sharing your knowledge. I am now a subscriber to your channel and found some other best videos. Thanks a lot man

  • @broomybroomybroomy
    @broomybroomybroomy 2 года назад

    Man, thanks so much for explaining how to update multiple object properties in the same statement. I was pulling my hair out trying to figure out how to do what you did with the spread operator. I was changing one thing with useState and it was wiping out everything else in the object

  • @sdfsdfsdffdsfsdfsd123
    @sdfsdfsdffdsfsdfsd123 2 года назад

    very well explained as always. THANK YOU

  • @suri5023
    @suri5023 Год назад

    very clear explanation and easy to understand
    thank you sir

  • @anaslaraki
    @anaslaraki 2 года назад

    the best tutorial on the topic

  • @wahhaab7
    @wahhaab7 Год назад

    Thx a lot, finally understood this

  • @farantariq3481
    @farantariq3481 2 года назад

    Best explanation I've found of reducers 👍

  • @Programming162
    @Programming162 7 месяцев назад

    thank you very much you saved my time

  • @ashharkausar413
    @ashharkausar413 Год назад

    Instructive as always. Wish I had seen this video earlier it would've made my code much more optimal!

  • @clevercoderjoy
    @clevercoderjoy Год назад

    wow this has been so helpful
    I was able to implement this in my project

  • @RS-iy2bm
    @RS-iy2bm Год назад

    The best tutorial i watched that made it all easy.

  • @mattstopa9436
    @mattstopa9436 3 месяца назад

    Thanks for giving a practical example

  • @phucwall121
    @phucwall121 Год назад

    Thank you so much Dave

  • @filippocamagni
    @filippocamagni 2 года назад

    Brilliant! Thank you so much!

  • @abdulazizmashrabov6399
    @abdulazizmashrabov6399 Год назад +1

    Thanks. You are hero. Awesome way of teaching. Hope you make more advanced blogs for react

  • @jeetsingh-sy5ij
    @jeetsingh-sy5ij Год назад

    Thank you sir, great explanation and examples. Appreciated!

  • @johnforeverrules
    @johnforeverrules 4 месяца назад

    i don't know whether you will see this comment or not. i just wanted to thank you for making such a high quality, easy to understand tutorial. God bless you sensei.

  • @THEJOAMS
    @THEJOAMS Год назад

    That helps me a lot 🙏

  • @lightrao
    @lightrao 2 года назад

    love you !

  • @gezafiqrullah5321
    @gezafiqrullah5321 Год назад

    thank you mr.dave :)

  • @ahmedmohned387
    @ahmedmohned387 2 года назад

    Thank you very much for this wonderful tutorial.

  • @MuhammadBilal-ry5rb
    @MuhammadBilal-ry5rb 7 месяцев назад +1

    Thank you so much SIr Dave I believe you are one of the best Programming instructor in the world right now all programming stuff available in your channel for beginners, intermediate and even for experts as well
    Thank you so much for your efforts and contribution
    I'm following you from last 1,2 months for ReactJS you are just amazing teacher I found on this platform
    Huge Love from Pakistan

  • @user-ki2xb3hk8r
    @user-ki2xb3hk8r Год назад

    Wow! Thankyou!!!!!

  • @da.b3102
    @da.b3102 2 года назад

    Great explanation! thanks!

  • @joakimwretlind4016
    @joakimwretlind4016 2 года назад

    Very nice! A really great explanation!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 года назад +1

      Glad it was helpful!

    • @joakimwretlind4016
      @joakimwretlind4016 2 года назад

      @@DaveGrayTeachesCode It really was. Do you have any suggestion on how to implement this for mouse movement, where you will have to pass x and y coordinates?

  • @iustin4172
    @iustin4172 9 месяцев назад

    Great video

  • @parasmehta7793
    @parasmehta7793 Год назад

    Thanks man!!

  • @dzentsetsu5607
    @dzentsetsu5607 2 года назад +6

    Very good tutorial yet again Dave! Just want to say it out loud, you really make me a better programmer with every new video. And I have a suggestion for a video... You see it really hard to grasp React for a beginner (even though I came with a diff prog. language experience) because it's so not intuitive and have so many caveats in developing process, SO it would be really helpful and useFull for us beginners if you could explain React pipeline in a tutorial video. For example, how React batching works (again basics), how component initially renders, how and why it re-renders... name a few. After watching your tutorial about calling useState twice in a row and not using prev => !prev was eye opening, but on another hand new question a raised why it working that way... Another example => I didn't know that React recreates a function and ALL inside it when state/prop updates. I think beginners will praise you for such a tutorial. Anyway, thank you so much again!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 года назад

      Thank you and thanks for the suggestion! 🙏💯

    • @taosit5282
      @taosit5282 2 года назад +2

      Yeah exactly! I don’t know how React really works and few people bother to explain it. I’m able to use hooks and make it work somehow but that’s just improvising most of the time. When the problem I face goes beyond the typical tutorial problems, I constantly add new hooks to fix the issues that the existing hooks create, without knowing why I even need the hooks I just added. I often find myself writing 10 useStates and 5 useEffects to coordinate the states within a single component. I’m often exclusively using hooks because I can’t be sure if local variables and functions would have worked. If they do, my code would have been so much easier to read and to maintain. A tutorial on React pipeline would be very useful!

  • @flowerofash4439
    @flowerofash4439 Год назад

    i lilke the way you explain this, you speak "human" thats rare to have as a programmer and very important for a teacher! subscribed!

  • @hamzapaskingakhtar
    @hamzapaskingakhtar 7 месяцев назад

    Coming here from NetNinja MERN course. I was stuck on the Context part where useReducer was used. This was really a great video. Great teaching, really matches with my way of learning (spoon feeding) :P. Overall, thank you professor.

  • @pedrojunior4516
    @pedrojunior4516 2 года назад

    Great tutorial.

  • @abdallahazouz5948
    @abdallahazouz5948 Год назад

    nice explanation ...thanks for helping me :D

  • @cleancode2123
    @cleancode2123 2 года назад

    Nice explanation of useReducer. 🙏

  • @djelasrca8091
    @djelasrca8091 Год назад

    Thank you for greath explanation

  • @juhairahamed5342
    @juhairahamed5342 Год назад

    Good explanation related useReducer

  • @sadamali6691
    @sadamali6691 2 года назад

    Waaaw thank you teacher dave greating you from somalia🇸🇴