The useReducer Hook

Поделиться
HTML-код
  • Опубликовано: 31 янв 2025

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

  • @fullstackspiderman
    @fullstackspiderman 4 года назад +1

    One of the best tutorial about React's Reducer hook. Your book and videos are always one of the best resources to learn React.. Thank you so much Dave..

  • @PhilipAlexanderHassialis
    @PhilipAlexanderHassialis 5 лет назад +2

    Jebus on a Harley, fastest most concise and easiest to follow mini-tutorial laser focused on a single hook. Well done!

  • @AndreColon
    @AndreColon 4 года назад +3

    Wow I have been feeling the imposter syndrome for sometime now - finding this video tells me it is not me. You found a succinct way to explain this an I salute you thank you!

  • @thuramoe9351
    @thuramoe9351 3 года назад

    Wow Wow Wow, very clear. I have stuck with useReducer, but now understand well. Thank you.

    • @dceddia
      @dceddia  3 года назад

      Glad to hear!

  • @cloudagnostic
    @cloudagnostic 6 лет назад +12

    This was a great explanation on the hook!

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

    Very well explained! I'm taking a React course on Udemy with 700,000 students, and somehow the teacher managed to garble this topic really bad, when it can be this simple

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

    A great example. Very well explained! Thanks Dave!

  • @NotAllHeroesWearCapes-101
    @NotAllHeroesWearCapes-101 5 лет назад +1

    very good tutorial. I would certainly encourage you to make more such videos !. thanks

  • @ganeshyandigeri1607
    @ganeshyandigeri1607 4 года назад

    It was awesome video I ever seen like this thank you so much I understood reducer hook concept. My special request is to make play list for all types of video.

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

    Most logical explanation for useReducer hook. Have been through many youtubers but most if not all do the example of counter and make the hook not more useful than useState. Thanks Dave, aside from being 3 years ago the tuturial, do you have any new useReducer tuts?

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

      Thanks! Glad it was helpful. Haven't got anything newer though sorry! 😅

  • @brothercaleb
    @brothercaleb 4 года назад

    This hook alone made me reevaluate my preference of other is libs/frameworks. Awesome functionality

  • @zakidev
    @zakidev 3 года назад

    Wow! You made it damn simple. I am your new subscriber. Thank you very much.

  • @kadekeqw23
    @kadekeqw23 5 лет назад +2

    Damn - amazing video. So clear, thank you. So from my understanding, useReducer is used when you have to manipulate state in a more complicated or complex manner than useState?

  • @jorgefelix4409
    @jorgefelix4409 5 лет назад +1

    Great example, I would like see all Hooks API explained like this

  • @xXxBladeStormxXx
    @xXxBladeStormxXx 5 лет назад +3

    Thanks, this is great! Can you also make one for useMemo?

  • @zvlehmlreano3002
    @zvlehmlreano3002 5 лет назад

    In your opinion which is better in production Hooks or Redux? anyway Great video sir.

  • @BromanThings
    @BromanThings 4 года назад

    Isn't initial state supposed to be an object and not an array? I'm thrown as to why you used an empty array for state when traditionally it would be an object at 4:40. Can someone explain?

    • @dceddia
      @dceddia  4 года назад

      Nope, state can hold anything. It doesn’t have to be an object. It’s pretty common, for sure, but it can be anything - an array, a string, a Boolean, a number, whatever.

    • @BromanThings
      @BromanThings 4 года назад

      @@dceddia gotcha, thanks for taking the time to comment. Learning hooks and react better, and it's all been really confusing but aside from that one question you explained everything great. Thanks again!

  • @arthurprather6720
    @arthurprather6720 6 лет назад +1

    Clear and concise. Thank you

  • @Ebbzzor
    @Ebbzzor 5 лет назад

    Fantastic explanation! Do you need useContext for these variables to be used globally through out the application?

    • @dceddia
      @dceddia  5 лет назад

      Yep, useReducer doesn't do anything to make the state available outside the one component you use it in. Context is good for that.

  • @strangestuff1213
    @strangestuff1213 5 лет назад

    Very well explained & succinct, thanks

  • @michaelporter2853
    @michaelporter2853 6 лет назад +1

    Nice video. Very clear.

  • @praveenlucifier8933
    @praveenlucifier8933 5 лет назад +1

    Clean and crisp 😍

  • @MrAlexGU1
    @MrAlexGU1 4 года назад

    That's basically how the Redux works - but as a more simpler and less bulky hook.

  • @rishusoni2494
    @rishusoni2494 3 года назад

    The best of the best.

  • @alexklein278
    @alexklein278 5 лет назад

    Great explanation, thanks 👍

  • @case_tips
    @case_tips 3 года назад

    I have Just FOund very Awesome Channel Thank you. do you have premium courses I am ready to buy

  • @WaterJay
    @WaterJay 6 лет назад +2

    ok, with this new hook api, how do you useReducer across, say, 2 different component, as everytime you useReducer, you create a new redux store. But if i have a component A and a component B, i want A to dispatch an action which change a state, then B sub to that state change and render the result, now you have A and B needs to be hook on the same redux store, how do you do it?

    • @dceddia
      @dceddia  6 лет назад +4

      As you already noticed, useReducer is meant for keeping track of *local* state, not global state. Even though it works like a Redux reducer, it's not backed by a global store. It's more meant for managing complex state within a component. But you can make it work similar to Redux if you pass the state & dispatch around with the Context API (and the useContext hook).

  • @ziyadkader6767
    @ziyadkader6767 4 года назад

    thank you very much .

  • @justfly1984
    @justfly1984 6 лет назад

    if you use type button on button submit, you don't need to prevent default

    • @dceddia
      @dceddia  6 лет назад

      With type=button, the button doesn't trigger the form submission but pressing Enter in the input does, and it refreshes the page. Give it a try: codesandbox.io/s/n51rvrrmlm

    • @justfly1984
      @justfly1984 6 лет назад

      @@dceddia So don't put formSubmit on form) put it on the button

  • @juhandvan
    @juhandvan 5 лет назад

    great teacher ! tks you very much

  • @hzrq
    @hzrq 3 года назад

    Ah.. Thanks for this!

  • @bartlebob
    @bartlebob 5 лет назад

    I know it's just an example but I want to point out that using big switches is of bad practice. It's breaking the single responsibility principle. Now the reducer has more than one reason to change.

    • @dceddia
      @dceddia  5 лет назад

      Switches are pretty common in reducers, at least these Redux-style state reducers, from most code I've seen. How do you write them?

  • @dean6046
    @dean6046 5 лет назад

    Thank you!

  • @luisavilesromero4735
    @luisavilesromero4735 5 лет назад

    Sir thanks

  • @parrou3
    @parrou3 6 лет назад

    Hi Dave, in case we want to fetch data from remote server and then pass it as initial state to a reducer, how we can proceed ? I tried to call dispatch inside useEffect but was rejected as per rule of calling hooks inside useEffect is forbidden

    • @kaos092
      @kaos092 5 лет назад

      Fetch your data in use effect and pass it to your state. Use effect replaces other lifecycle methods

  • @ukeskin
    @ukeskin 3 года назад

    Wow ❣️

  • @MrJohn360
    @MrJohn360 5 лет назад

    Neat, thanks for sharing!

  • @claytonvanderhaar3772
    @claytonvanderhaar3772 3 года назад

    Hi great video, please if you can help me I need to increment and decrement an item from one onClick event fetching sensor data from an api get request

  • @keb777
    @keb777 5 лет назад

    Hi Dave,
    Can you please make a video about Redux-ORM?)

  • @patricksjoberg9011
    @patricksjoberg9011 5 лет назад

    I dont understand what is new about this?
    Have they just inplemented redux into react.
    With that I mean, this looks like an dispatch action...?
    Whats the advantage of using it in a component? Or is that the awesome thing about useReducer?

    • @dceddia
      @dceddia  5 лет назад +1

      Patrick Sjöberg it’s the same concept as a Redux reducer, but localized to one component. When your component state is more complex (like you have a bunch of useState calls to keep track of), useReducer is a nice way to combine those things, and the reducer logic can be pulled out into a separate function and reused.

    • @patricksjoberg9011
      @patricksjoberg9011 5 лет назад

      @@dceddia ahh i understand now. Thanks!

  • @edilsonfb
    @edilsonfb 5 лет назад

    Very good

  • @lamphanp
    @lamphanp 5 лет назад

    Remove item should use id instead index.

    • @dceddia
      @dceddia  5 лет назад

      "Should" implies using index is "wrong", but either way works as a way to find an element once. (unlike using 'index' as a component key, where it's not a good idea). Using the id would've been idempotent and probably slightly better from that perspective though.

  • @adoreos
    @adoreos 5 лет назад

    Hey I have the dumbest question ever: what theme are you using?

    • @dceddia
      @dceddia  5 лет назад

      Dor Bens that’s Sarah Drasner’s Night Owl. Love that theme!

  • @skube
    @skube 5 лет назад

    Great stuff as usual Dave!
    I think you could avoid the `useRef` by use of the `event.target.elements` as demonstrated by KCD ruclips.net/video/kCR3JAR7CHE/видео.html

  • @rahultv97
    @rahultv97 3 года назад

    Did I find God 😇