3 Minutes with Kent

3 Minutes with Kent

By Kent C. DoddsTechnology
Download on the App Store

All 3 Minutes with Kent episodes

  • Join the KCD Discord and request podcast topics

    https://kentcdodds.com/discord

    Hey there friends I want to make an invitation to you So yeah you're not

    gonna learn a whole lot in this one. Feel free to skip if you want but my
    invitation is I opened a well reopened channel on my discord you can find
    it at Kensie dots.com slash discord and that channel is three minutes with
    Kent and so that's a place for you to discuss the episodes but more
    importantly in the reason I'm bringing it up is it's a place for you to ask
    for particular episodes so you can ask questions or you can say hey, what
    do you think about this or whatever you want to andHopefully my answer can
    be within three minutes if it can't then or you have like, hey I have a
    block of code that I want you to review or something like that.

    If that's a case then you can actually come to my office hours which you'll

    find at Kensington / office hyphen hours. In any case, yeah, I just invite
    you to come to my discord. It's a fun community, we're awesome. It's a
    great. I prefer hanging out on Discord way more than I like hanging out on
    Twitter.

    And so yeah, it's a fun place and there's a special channel the three

    minutes with Kent channel where you can.Talk about different episodes and
    you can with other people who listen myself included. And you can request
    topics and ask specific questions and stuff and and I have plenty of ideas
    of things that I want to talk about on this three-minute podcast that we
    enjoy each and every day.

    But yeah, I'd love to hear what you all would like to me to talk about. So,

    I'm not just trying to create this thing in a vacuum. I want to make this
    be something that's more of a I don't know. Inspired by the things that
    you.Do want to hear.

    So anyway, so you go to ketots.com slash discord to go join the discord and

    enjoy all the other awesome topics that we've got there. We have a channel
    about just life outside of software development. We also have a react
    specific channel and a the yeah, it should be I should just like pulled up
    and look at and and just list off we have the KCD clubs is in there.

    There's also an OSS raid group that's open source group of people who like

    go on these raids where they do.Just contribute a ton of stuff to different
    open source libraries and projects and stuff. It's really really cool. So
    that is organized there. We've got some like my own stuff so I do live
    streams there coding live streams and and my office hours every Saturday.

    So yeah, it's a good time. So if you come for no other reason than to just

    be a part of all of that, that would be cool, but then also have that
    special channel for this podcast. Anyway, I hope you have a marvelous day
    and we'll see you hopefully on the discord.

    Bye.

    3 min
  • Write it both ways

    Hello friends, so today I'm driving so that's the background noise you're

    hearing but I wanted to talk about how I make a decision about which
    direction to go when I'm talking about like writing code in multiple ways
    so like when the writing code there's like infinite ways to do things and
    you really can just slice this in any direction that you choose and lots of
    those decisions are pretty arbitrary and,Yeah just like it's not so cut and
    dry it's subjective and so the best method that I've found now sometimes
    you can't really do this, but if it's for like a you know, utility function
    or a handful of utility functions or something like that the best method
    that I've found for fixing or determining the best approach is to just take
    both approaches and so this may take a little bit of time depending upbeat
    how big the thing is, but you just build it one way and now you have a good
    idea of what the requirements are for.

    That method of madness and then you build it in the other way and you get

    an idea of what that looks like and then you have way more context to know
    which way is the better approach for whatever you're trying to accomplish
    and so it may be it will take a little bit more time, but it's I I think
    that it's worth the investment if you're concerned that one way might be
    better than the other and sometimes if it if it's just like a small utility
    function like the one that inspired me to talk about this today was just
    like a 20 line function and so like it.

    Didn't take me a whole lot of time to try both and then you know comment

    out one coming in the other and just see which way I liked it better and
    yeah and and so like you don't have to just always go with the first way
    that works. I think we do this a lot and we don't really have to do it that
    way so anyway.

    I hope that is marginally useful to you at least and really interesting and

    insightful to you at best and yeah take care.

    3 min
  • Tell the boss how great you and your co-workers are

    Hey friends so today I wanted to talk about how important it is to

    communicate and in particular I want to highlight the importance of
    communicating what you and your team have done to your higher-ups. So
    anytime that you or your member of your team does something spectacular you
    should send an email to your boss or to your teammates bought.

    So there's nothing wrong with saying hey boss, I did this thing and it was

    really difficult and I really glad that it worked out and I just wanted to
    let you know kind of celebratory whatever.Theres there's a way to do this
    that isn't cocky um and the way that you do that is most of the time you
    don't accomplish this without the assistance of anyone else.

    And so you can say, hey I boss like I had this problem and I worked with

    these other people and we figured it out and we just did an awesome job and
    I just wanted to let you know that your team is awesome. I love working
    here. A Boston lab stitch here emails like that.

    You can also do this if it wasn't your accomplishment, but somebody else's

    and so you'd say, hey, I just wanted to you to know that Sammy did.This
    amazing thing and she's just a rock star awesome person and yeah, I love
    working with her whatever you wanted to say there um, and I think the
    reason that I think that this it's important for you to communicate these
    sorts of things is most of the time like this is the manager's part of the
    manager's job is to get an idea of what's going on on the ground, like
    actually working on the product and it just helps them to accomplish their
    job, but it also helps you to communicate to your boss the sorts of things
    that you like to work on.

    So,You know if you really enjoyed working on this particular task, then you

    say I loved working in this it was really awesome opportunity. Thank you
    for giving me this opportunity. If you didn't really like it you say, hey I
    accomplished the thing. I'm glad that it's over. I never want to work on
    this again.

    It just gives you an opportunity to connect with your higher-ups. And if

    you're saying something like this to someone else's boss that's even better
    because it makes that person and you don't have to include them you might
    like BCC them.On the email to their boss's boss or whatever But it makes
    them feel really good and feel a connection and maybe there will be some
    reciprocity, but that's not why you do it.

    It just it increases the positivity in your organization, which I think is

    good. It might give them a pay raise whatever and especially for those of
    us in privilege positions. I think that it's really useful to do this as a
    mechanism for lining your privilege to so I would really recommend this for
    you in that position.

    So anyway, I hope that you take an opportunity this week and just like,Find

    something that you can send to somebody's boss or your own and do it. See,
    ya.

    3 min
  • How to test Redux

    Hello everyone. So today I want to talk about testing redux. So I know that

    I don't really use redox like a lot of people know that I am not a huge fan
    of redux any redex project. I worked in would just became very difficult to
    work in. But I know that a lot of people are using redux and especially if
    you are probably using redux tool kit, which is great.

    So anyway, as far as testing redex goes. You shouldn't actually ever be

    testing redex. You pretty much always want to test the components that are
    using redux.And only sometimes when you have maybe something that's really
    complicated and redex or something you should probably extract that
    complicated logic into its own pure function and test that by itself.

    But most of the time you don't need to bother most the time just rest the

    components that use redex you wrap your component inside of the the redex
    store provider and everything and and and then just test it as if it's not
    using redex and the benefit to this is if you decide that oh this state
    doesn't need to be in redox.

    I can move this to local state or whatever then that's

    actually.Straightforward to do and the test will help you confirm that you
    didn't break any behavior in the process of doing of doing that. And on top
    of that, you can go the other way too. So if you decide, oh this state
    needs to be in redux, if you've written your test so that everything's
    wrapped in the ReadX context provider, then moving it over to redex the
    test should be able to tell you that you didn't make any mistakes in that
    process either.

    So readax is an implementation detail. Don't bother testing read

    explicitly. I don't test my action create.Ters I don't test yeah or when I
    was using readx I didn't test the action creators didn't test the reducers.
    I tested the components that use those things and I didn't mock those those
    things.

    And on top of that you also get your map dispatched to props and whatever

    else those I can't remember what those things are called anymore, but you
    don't need to bother testing those in isolation you get those covered
    because you're testing the component the connected version of the
    component.

    So, you don't have to worry about refactors breaking your tests, the the

    test can actually.Give you confidence in the refactor. Hopefully, that's
    helpful. Have a awesome day. We'll see you around.

    3 min
  • TypeScript: Don't type array method callbacks

    Hello friends, this is a little bit later than usual but I just wanted to

    get this in because I want to do this every weekday. So today I want to
    talk about TypeScript and in particular map. So I wrote a blog post
    recently that talked about converting typescript or fetch a fetch
    implemented or calling fetch in a function over to TypeScript because when
    you call fetch the return value from the dot JSON on that response is going
    to be any and so you have to explicitly.

    Give that a type annotation. And anyway, one of the as I was migrating this

    code one of the things that I pointed out was that like we were iterating
    over some of the values that came back from that response.json call. And in
    the process of migrating the code if you just go about it in a certain way
    before you add the type annotation, you'll find that iterating over it
    requires that you type that map.

    Callback function. And so in our example, we had an array of errors that

    could come back from this API call and we're going to iterate over those
    array of errors to kind of join them up into a single error. And so the
    idea in in this example was you would get a implicit error or implicit any
    problem on that map callback function and as a result you had to type that
    explicitly and so I just say okay, well the argument to this is.

    An object that has a message property. So anytime you are you have a dot

    map call on an array and type script is telling you that you have to give
    an explicit type to the arguments of that callback function. This would
    also apply to like a filter or any array of any kind.

    So anytime that callback function requires that you add type annotations.

    That is a sign that the array itself is not typed. So you want to skip the
    whole typing of that?Callback function and go back to where that array
    itself is defined and make sure that it has a proper type annotation of
    some kind so that you don't have to worry about typing the callback for an
    array method.

    So if you're ever doing a radon map or a radar every or a radar sum or a

    radar filter or reduce or any of that and type script is saying, hey, I
    don't know what type this is. This isn't implicit any you need to add a
    type for this function.

    Don't do that go fix the array first. Hope that's helpful. Take care.

    3 min
  • Where do unit tests fit?

    Today I was in a piano discussion for test JS Summit and a question was

    asked about like what's the use case for unit tests if we focus on
    integration and component level tests. And I talked about this and and it
    was kind of more about like what what's the shape of our testing trophy or
    testing pyramid or whatever like where do we focus our tests?

    And I talk about how I recommend that you focus on integration and

    component-type tests and try to mock as little as possible. I typically
    don't mock modules all that often and most often will just.Mock HTTP
    requests unless we're doing end tests in which case you mock nothing. And
    the the way that I think about it is like if you just have 100% unit tests
    and that's all that you're writing and you get a hundred percent code
    coverage with that you're still very likely to have lots of bugs creep up
    as integrations between different pieces of these units change.

    And that can be very difficult to track when you are just mocking all the

    modules and just unit unit testing everything. And so you're gonna start
    moving over to component or integration.And type tests and with that you
    end up realizing that you don't need those unit tests as much because
    they're covered by the integration test and so okay now we just don't
    bother writing those and we just focus on integration tests but event at
    some point if you just say, oh let's just do all integration tests you're
    gonna find that it's a lot very repetitive to cover certain cases.

    Maybe you have some functions that are doing some computations in there a

    lot of different parts of the algorithm that you're using or whatever, you
    know, tons of branches if statements turn areas all over the place that you
    have to cover.To you know feel confident that you can ship this code And so
    those are the types of things that I actually move over to unit testing.

    And so we'll have a single integration task that's or maybe a handful of

    integration tests that are testing the more common use cases, but then
    you'd have a unit test for the specific unit of code that is more complex.
    It's typically these are going to be pure functions but not always but
    they'll often be pure functions that you just call it with some arguments.

    You get some result back. And these types of tests run really fast and

    they're really quite easy to run.And maintain and so that's kind of where I
    see unit tests fit into the spectrum of what types of tests that you write.
    I've written about this on my blog.

    If you go to https://kcd.im/trophy, you'll find it it's a static versus

    unit versus integration versus end testing. A kind of lays out the
    differences there. Anyway, I hope that's helpful to you have a wonderful
    awesome day and we'll chat with you later.

    3 min
  • Creating Content: My Secret to Learning

    Hey there friends So none of you are content creators none of you aspire to

    that or anything but I kind of want to change your mind on that a little
    bit. Creating content isn't just for the people who are out there creating
    content and getting paid for it like me or whatever I didn't start getting
    paid with the concept that I create and much the content.

    I create is actually not paid. My but like I often actually get asked about

    like, how do you learn stuff and and how do you like know the stuff that
    you know. And and my answer is that I kind of cheat and I say, hey, I want
    to learn about.

    How to use Angular with React and so I'm going to make a conference talk

    proposal that is that. So, I know it's possible. I just I've never done it
    before maybe but I know that it's possible. So I'm going to make a
    conference talk proposal. It gets accepted and so now I have like, I'm
    forced to go and learn this thing.

    And in the process of creating that content, I'm learning a lot about both

    of these frameworks. So creating content is a mechanism for solidifying in
    your mind the things that you want to learn about. And so this is why I
    want to encourage you to write a blog or create content.

    In whatever form you want but blog is pretty straightforward most people

    can do it without too much trouble And your first couple blog posts may not
    be very good and that's totally fine but as you do it more you're going to
    get more experience and you'll get better at it.

    So don't worry about it and and really your goal isn't necessarily to

    create this blog that everybody reads and it's the next thing CSS tricks or
    whatever maybe that's what you want to do, but that's not relevant to what
    I'm talking about. Your goal is to create the content and force yourself to
    think about the things that you're writing.

    I'll give you an example yesterday.I was writing my weekly blog that I

    decided I do a weekly blog a couple years ago and it's been going for a
    while and it's awesome. And I was writing in my weekly blog. I grabbed some
    code that was in one of my workshops.

    It was a fetch implementation for fetching Pokemon using this API. Anyway,

    and as I was writing the blog post, I realized that there was a small bug
    in my implementation. Even after I moved it over to TypeScript, there was
    still a back. In fact, I found two now I think about it.

    And so in the process of creating this blog post, I learned.More about the

    code that I was writing about So this is just wanting of many many examples
    Like I've written libraries based on things that I learned as I was
    creating content. In fact, testing library Dom testing library cypress
    testing library react testing labor all of that came because I was creating
    content on how to test and and then I decided oh this is too hard.

    I'm gonna make a library to do that. So anyway, I would encourage you to

    take a little bit of time to write down what you're learning create some
    content to dig a little deeper into the things that you feel like, you
    know, really well.I hope that helps have a wonderful day.

    3 min
  • Automation with Cypress: Renaming GitHub Repo Default Branches

    https://github.com/kentcdodds/rename-gh-to-main

    Hello there friends. So today I'm going to talk about what I did yesterday

    and that is I spent just like an hour to renaming all of the default
    branches on my GitHub repos from Master to Maine. Now, I'm not going to
    really explain directly why I actually have a article that you can go read
    but Git and and GitHub are moving the default branch from master to main
    fork historical reasons and you know references to slavery and that sort of
    thing.

    And so I decided I wanted to support that and I wanted to.Get everything

    consistent but I have over almost 300 repositories where it's the source
    repository not a fork I have. Yeah, just a lot of repositories. I didn't
    want to spend all the time. And as far as I know there's no GitHub API for
    for updating the default branch from Master to Maine.

    And so I needed to use the UI. So what I did yesterday is I actually

    livestream this and you can go watch it, but I used Cyprus to automate
    navigating to every one of these repos. I wanted to and,Rename and we'd go
    to the slash branches URL for each one of the repos and select the the
    little edit button for the default branch and then enter main as the name
    and then you know rename the branch and click that button.

    It was actually pretty straightforward. They're just a handful of lines of

    code and it's all open source you can go take a look at how it it's all set
    up but it was really cool to write this really quick. Cyprus quote-unquote
    test automation and and see it in the browser and what was cool is the way
    that I was able.

    To develop it because Cypress actually pulls up a real browser and you can

    interact with that browsing you can type in and because I was live
    streaming I didn't want to actually have Cyprus enter in my username and
    password so I was able to have it pause the execution of the test so that I
    could take the browser off of the window and type in my username and
    password and then have a proceed and and go through everything.

    So you should go take a look at that. It was like an hour and a half you

    could speed it up and just skip to the parts that are interesting. But
    yeah, it was pretty pretty cool and I I like using Cyprus for this sort of
    thing.If you were doing like legit long-term web scraping or something,
    maybe puppeteer would be a better fit but Cyprus makes manual processes
    like this like just so nice and easy.

    So yeah give that a look. It's kind of interesting and I hope that you find

    it fascinating and fun and I hope you have a marvelous day. Bye.

    3 min
  • How to approach writing tests

    Hey there friends. So today I'm going to talk about testing and the users

    of your code and how you should think about like how what do I test? So
    pretty common question. And the answer is basically you take a unit of code
    that you want to have tested that could be a single function or it could be
    an entire application.

    It really just comes down to what you want to get confidence in. Most of us

    are probably in the camp of like I just want my to be sure that my entire
    application works and that's great. And that'sTypically where where I'm
    thinking and in my own mindset sometimes though, it's hard to accomplish
    the thing that you're trying to test from a whole application perspective
    and that's when you go to lower level forms of testing but that's not what
    I'm going to talk about today.

    So once you've identified the unit of code that you want to have tested the

    next thing you need to do is think about who the users of that code are. So
    if we're talking about a react component, for example, then you're going to
    have two users of your code.

    And in fact most of the time,You're going to have two users of your code,

    unless you're doing full-on and to end testing with nothing mocked. And the
    two users are the end user who's going to be interacting with that code and
    the developer user who's going to be making network requests to your API
    handler or maybe they're calling into your function or their rendering your
    component, whatever it is.

    So you have those two two users of your code. And so then as you're

    thinking about what you know, what you should write.For your test you're
    going to say okay well so what is the what do mind users do What are the
    use cases that this code supports and how do I make like what are of those
    use cases what are the most important things that I ensured don't break?

    Because they're like for an application there are some parts of the

    application that matter more than others. And so you're going to identify
    all the use cases that you want to support and kind of sort them in your
    mind or maybe even write it down. The order of priority for those things.

    So once you have decided what use cases you want to support you just go

    one.By one to write a test for that particular use case. And the way that
    you write that is you could even write this in code comments or something
    before you write the test you just say how do if I were a user manually
    testing this whether you're the end user or the developer user probably
    both how would I interact with this component to make it do the thing that
    I'm trying to support?

    How do I show that use case in my test? And then you write code to do that.

    I hope that's helpful and I hope you have a splendid day. Good luck.And
    writing those tests get yourself a lot of confidence and we'll see you
    around.

    3 min
  • Don't Side-step TypeScript

    Hello everyone So today I'm going to talk about TypeScript and tricking

    type script versus fixing your code So, you know, the the null non-null
    assertion thing where you put the exclamation point at the end of something
    to say, hey type script this isn't going to be no or whatever.

    I don't really use that. There's actually two reasons. One of them is

    because it looks like when you're looking at the code that looks like
    that's a feature of JavaScript, but it's not and so I don't really like
    using things that look like they could be a feature of JavaScript but
    aren't I don't know maybe that's just weird of me.

    But the the biggest reason is that most often if TypeScript thinks that

    this can be null it's most likely that it actually can be no and and you
    could put that bang there or you can do type assertions or casting and
    whatever but it's I I don't like telling TypeScript that no this like this
    won't be this value when it actually could be that value.

    So I'm thinking about a specific example that my friend Peter on discord on

    during office hours today brought up and I was.Live streaming and I was
    reading a value out of local storage and and then parsing that with JSON
    down parse. And JSON parts can technically accept anything and then it
    stringifies it and so you can pass it null it will stringify it to null and
    the result will be null.

    Sorry, it will stringify it to the string of null and then the result of

    parsing that will be no. And so yeah, you can just pass in no but the
    typescript definitions for that except specifically a string. It has to be
    a string that you pass to it. Even though you can technically pass anything
    and it'll just get stringified automatically.

    So,What I did was I did the double question marks, whatever that's called

    the I can't remember what that operator is called but yeah. So I'd say okay
    read in the locust storage if that's null then it will just pass in the
    string of null and then that will result in an old value.

    And he suggested that oh why don't you just do a bang on that on the end of

    that and then that should work just fine just say, you know, hey type
    script this is not going to be null, but it actually will be it'll just be
    okay that it'll be null.

    And so,But he also suggested you could also just pass it to the string

    constructor and then that would stringify null and then you could pass it
    in And I opted for passing it to the string constructor because I don't
    want to tell TypeScript that this will never be this null value.

    What it actually will be in reality. And so it's not just communicating to

    TypeScript. It's also communicating to the other people who are going to be
    reading the code. So anyway, I hope that's sort of useful and train of
    thought try not to convince. TypeScript that something will not be of a
    certain type what it actually could be.

    Hope you're having an awesome day, we'll see you all next time.

    3 min