useReducer with TypeScript

Поделиться
HTML-код
  • Опубликовано: 15 июл 2024
  • Today we're adding TypeScript to useReducer!
    We're taking the code we built with my "Why I love useReducer" ( • Why I Love useReducer ) video and making it type safe!
    Have a watch!
    Source code: github.com/hswolff/youtube/bl...
    --
    NEWSLETTER: tinyletter.com/hswolff/subscribe
    PATREON: / hswolff
    TWITTER: / hswolff
    SITE: hswolff.com/
  • НаукаНаука

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

  • @Deliverant
    @Deliverant 4 года назад +31

    Every Typescript video is extremely appreciated, thanks Harry.

    • @hswolff
      @hswolff  4 года назад +2

      Glad you enjoy!

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

      So true :)

  • @wt_wt0
    @wt_wt0 4 года назад +5

    I'm genuinely surprised with how Typescript is that powerful. Thanks for sharing it man!

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

      Yeah, same! Some of the type inference and passing along of types is really really fancy.

  • @WTHBrou
    @WTHBrou 3 года назад +1

    I couldn't diggest this topic like 6 months ago but now I came back from a 4 months hiatus of TS and React and I can understand it clearly. Keep on these videos!!

  • @AnupDhakalSharma
    @AnupDhakalSharma 3 года назад +1

    Love your way of teaching; I am in a binge! I especially liked how you subtly showed how to make impossible states impossible using powerful unions!

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

    I started to learn typescript, and your videos are really helping. Keep them going!

  • @Digibeario
    @Digibeario 4 года назад +2

    Great job Harry! Another video with advanced typing examples. Right on!

  • @Alexandru-OM
    @Alexandru-OM 3 года назад +1

    This made perfect sense, also having a useReducer in front of me and working along helped :)). Keep it up, thank you

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

    All clear. Love your explanations!

  • @KuldeepYadav-jw7jn
    @KuldeepYadav-jw7jn 4 года назад +1

    Hey Harry, I really liked the content and TBH, the only video over youtube which explains it so easily, thanks

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

    Bro, your videos are PURE GOLD! Thank you so much 🙏

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

    I love your typescript videos

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

    Harry, thank you for your explanation, it helps with my current TS learning path

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

    Super useful explanations! Thank you.

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

    Nice, love your typescript videos. Actual hands on projects videos would be cool too!

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

    Great Tutorial helped a lot especially after watching the JavaScript related one

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

    Really loved this, Thanks!!!

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

    Thank you very much for a nice and clean tutorial.

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

    This is great! Love these videos

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

      I'm glad these are resonating!

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

    Awesome! I learn a lot from this. Many thanks :)

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

    Explained well. Thank you 🙂

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

    So, so good. The content is small enough to digest and the topic is very focused to one small piece of React. I'd love to continue seeing these videos from your channel. I do have a quick question for you about interfaces vs types, how do you go about determining when something should be a type vs creating an interface?

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

    Good tut, thank you

  • @BharatSingh-zk8lx
    @BharatSingh-zk8lx 3 года назад

    Thanks a lot... Helped me a lot haha. Appreciate ur efforts. New Subscriber.

  • @notjuststartups5904
    @notjuststartups5904 4 года назад +2

    I love your videos. Can you make a video showing one of your larger react development projects and how you organize your code typically? Do you do a global useContext? What sort of npm packages are your favorites? etc

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

    Thanks a lot!

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

    there are a few videos on RUclips talking about TS especially with Hooks. thank you for your effort

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

      You are very welcome!

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

    I love this video

  • @user-zy6me5vn2f
    @user-zy6me5vn2f 4 года назад

    cool harry thank you!

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

    Nice. More React-TS stuff please!

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

    Which font is being used in this video... I loved it ❤️

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

    This video inspired me to try and make some helper types that let you express your actions in a nicer way. You can put these types somewhere in your application and import them whenever you need them.
    type ActionsWithTypes = {
    [K in keyof A]: { type: K } & A[K];
    };
    type ActionUnion = ActionsWithTypes[keyof ActionsWithTypes];
    type Reducer = (
    state: State,
    action: ActionUnion
    ) => State;
    How do they work? For the login example, you would have to create an interface like this:
    interface LoginActions {
    field: { fieldName: string; payload: string };
    login: {};
    success: {};
    error: {};
    logOut: {};
    }
    You could then use ActionUnion directly or type your reducer function with Reducer.
    const loginReducer: Reducer = (state, actions) => { ... }
    Auto-completion and type inference work the same as in the video. The drawback is that it's much more verbose if you have a lot of actions without payloads. The advantage is that it is - in my opinion - much more expressive. Feel free to use these in your project if you like them.

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

    can you please explain more about typeof with examples?

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

    Was just listening to Front end happy hour podcast - and guess who has only gone and been mentioned! I was like 'yeh! That's my host. Harry Wolff... With him... Harry Wolff'

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

      Hahaha, awesome! I love the FEHH people! They're terrific!

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

    8:48 what if the payload is not always string but is dependent on the property which the fieldName is referring to?

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

    could you plz do a video that useImmerReducer and useContext with Typescript?

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

    Have you used Flow with React at all? We are currently debating whether to use Flow or Typescript for our React project. The app is pretty big, so it's definitely not an overnight migration. Any insight you have would be helpful.

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

      Hey Agrawal, how are you doing?
      We've passed through the same situation here at the company I'm working for. We found that Typescript is the most logic approach to long-term support and scalability. It's actually a mess to discuss about the future of typed javascript, for me, in the end it always comes down to choosing the most confortable stack for the team.

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

      We actually started using Flow at work before quickly switching over to TypeScript!
      Flow is primarily built for Facebook's needs and isn't really a community project IMO. Meaning that Flow is built for Facebook and TypeScript is built for the community.
      I'd heavily recommend TypeScript over Flow.

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

    @Hrray wolff debug vsCode plug-in is?

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

    It would be really helpful if you make a video how useReducer and Redux work. just thought

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

    you should do a series of react hooks with typescript!

    • @hswolff
      @hswolff  3 года назад +1

      Oh that’s a great idea! Thank you!

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

    Can you recommend a guide on when to use an interface vs type?

    • @hswolff
      @hswolff  4 года назад +4

      Are you asking me to make one? 🤔

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

      @@hswolff Why yes....I believe I am!

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

      @@hswolff That would be nice. :) In a framework ive even seen a class being used to make a type -> class X = {something:string}

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

      have you read this post? stackoverflow.com/questions/37233735/typescript-interfaces-vs-types

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

      Can you please make one, this would be amazing

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

    TypeScript Union type in ACTIONS, does not work for me

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

    Love your video.. I prefer that if you can shrink your headshot area little bit.. I know you are handsome.... ;)

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

    Interfaces in TypeScript are super confusing for C# developers. In one case you used Interface and then you changed to Type. Why not using Type all the time?

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

      Sounds like I need to do a deep dive into the differences between an interface and a type....