3 Minutes with Kent

3 Minutes with Kent

By Kent C. DoddsTechnology
Download on the App Store

All 3 Minutes with Kent episodes

  • Why I love Magic ✨ Login Links

    Hey friends So I am working on a rewrite of my website can see downs.com

    and one thing that I'm adding is user accounts so you can set up an account
    and I'm not going to tell you why you might want to do that. I have a
    little bit of a surprise.

    But the reason that I mentioned this is because I'm using Firebase

    authentication and I started out with the username and password regular old
    username password sort of thing that you're used to. And it worked pretty
    well. I had a password reset. I had forgot my password. I had changed
    password and updated email all that stuff was all implemented butIn as I
    was working on all of this I started to I think personally I actually
    really like the magic link for stuff because for various reasons it's it's
    incredibly more secure.

    So like if I were to have a data breach which of course, it wouldn't be me

    it would be Firebase I would have the data breach. So, I'm not really
    worried about that. But if that were to happen or rather for services that
    I use I prefer and that they use magical links because if they were to have
    a data breach all that's lost is my email address, which is,Everywhere
    There's nothing secret or private about my email address.

    They wouldn't be able to get my password. And I do use a password manager,

    but I wouldn't need most lots of my family doesn't use password managers.
    They have either some sort of algorithm. They've come up with for
    generating passwords, which I used to do actually or they have they just
    reuse passwords or whatever.

    And so data breaches don't reveal any passwords of any kind. And so that's

    it's way more secure in that way. Because there's just no data to lose.
    But,The other nice thing about this is or or the like the biggest concern
    that people have with this as well. I do use a password manager and if you
    don't have a password then I can't put you in my password manager.

    And no, that is false. You can definitely create a an email only entry in

    your password manager. And the reason that you'd want to do this is if you
    have multiple email addresses, or you use email aliases or something.
    Sometimes you can forget which email you use for a given service.

    So you just add an entry to that email or password.With the email that you

    use and just don't have a password. And then it makes the implementation
    way easier as well. So there's no need to worry about password reset or or
    securing the password or changing the password or any of that.

    So like forgot my password all that stuff just goes away. So you can get

    rid of a ton of complexity just by eliminating the password. So I am all in
    on magic links. I think that they're great and if you don't log people out
    automatically after a couple days then or you keep them logged in for a
    month or so.

    Then,There's no problem with the user experience either. Have a good day.

    3 min
  • Use Super Simple Starts to learn new things

    Hey friends So some of you may be familiar with my super simple start

    series of blog posts. I've got like six or seven of those and basically the
    idea is let's strip down everything else outside of the thing that we're
    trying to focus on and just bring in the abstractions or tools that are
    100% necessary for whatever whatever it is we're learning and that means if
    we're talking about CSS variables or custom properties, that means we're
    not bringing in Webpack or any of that nonsense, it's all just index HTML
    and then style sheets and stuff.

    And we're talking about react same story. We get rid of the build tools

    just get rid of all of that stuff and see how minimal we can make something
    work just kind of the hello world of this. We we don't care about whether
    this solution scales or anything and the idea is if we can separate the
    specific thing that we're trying to learn from all the extra things you
    need around it to make something practical you'll understand a lot more
    what the the role of that thing that you're trying to learn is.

    And so,It just has helped me enormously where with regard to working with

    node modules like native ES modules or even the native ES modules in the
    browser. And so this is something an approach that I take when I'm trying
    to learn something new or maybe when I'm trying to introduce something new
    to somebody as I try to just pair it down as much as I possibly can to
    remove all of the noise and just focus on what we're trying to actually
    learn and it's been really effective and so I wanted to share that with you
    as an.

    Idea if there's something that you're trying to learn and you want to just

    really get a solid grasp or understanding of a specific technology or
    whatever then try to make a super simple start to whatever it is that
    you're trying to learn. And I think that you'll find it's surprisingly easy
    to do typically or it's a lot easier because you can just ignore a ton of
    other things that we always have to think about when we're building real
    apps.

    And then it also helps a great deal and actually being useful. So anyway, I

    hopeThat's helpful and I hope you have a wonderful day.

    3 min
  • Trust the process

    Hey folks, so today I want to talk about trust the process which I just

    barely looked up and apparently it's a slogan used by fans of the NBA's
    Philadelphia 76ers and now it's just everybody uses this and I use this and
    one of the things I think that I mentioned on three minutes with Kent
    months ago, when I started this new year one of my or my kind of goal or
    theme for the year was planning and the way that I executed that theme was
    I have a notebook and a pen that I keep in my pocket.

    And at the beginning of the day I'll just look at my calendar and the

    things that I'm I need to do or maybe at the end of the day for the day the
    next day and I write down a list of all the things I want to get
    accomplished and so far this year.

    I've done a really good job of keeping up with that process it's worked out

    pretty well. I had slipped up a couple times for like when we do spring
    break and stuff with the kids, but for the most part I've been doing this
    really well and it's worked out just phenomenally so I it's a pretty small
    thing.

    But it's it makes me feel a lot more productive especially during on those

    days where you don't really feel like you get a lot done and you can look
    at your list at the end of day and say yeah sweet I did get a lot done or
    maybe like wow that one item on this list just took the whole day.

    I didn't expect to expect it to to take all that time, but at least you can

    kind of reevaluate and think about the things that you got done and you can
    prioritize things and make sure that you don't spend so much time on the
    little things on your list that you miss the more important things and so
    you.

    Can see it all in front of you and prioritize so this is worked out really

    well and there are times where I think man I'm just not getting as much
    done that I want to but then I just trust in the process and make sure that
    a I'm being as productive as I can and I can't really ask much more of
    myself so anyway for today.

    I just want to encourage you to trust in whatever process you come up with

    and if you don't have a process, you don't have a goal or something
    specific that you're trying to achieve then I recommend that you get one
    and actually it's Scott Hanselman was on.Chats with Kent a while ago and he
    and I had a great conversation about being intentional about what you want
    and about how you spend your time and I just listened to it again today.

    I'd suggest that if you haven't listened to it already go listen to it and

    if you have give it another listen because it Scott is just really
    inspiring has a lot of really good ideas and so yeah, if you haven't
    listened to that go go to https://kcd.im/podcast and give that a listen.

    I hope that's interesting and helpful to you have a wonderful day.

    3 min
  • Mock logs in tests

    Hey folks So I have had a couple of in situations when I was writing some

    tests where I had some code that would give me some sort of warning maybe
    it's using the invariant module or I'm just doing a console.air or
    consultant more or something like that. Or maybe I'm rendering a React
    component that will throw an error or something like that and I want to
    write a test to make sure that that error is thrown or whatever.

    So in in these sorts of scenarios, you're going to get console.errors

    getting logged. And so, I just wanted to talk about how I do that. So what
    I do,Is I am I do just that spy on console error and do that in a before
    each and then inside the test itself.

    I will define what I want it to be mocked as and I don't want to have my

    tests muddied up by all the console output from my source. So whether
    that's console.org, or error or log or anything, I want my test to be
    totally free of all of those things.

    And so if I'm expecting to have some logs of some kind as I'm running my

    tests, I'm going to need to mock all of those things. So that I don't have
    aBunch of noise in my test output And so typically console.ir is going to
    be mocked and I'll say mock implementation empty arrow function, so it
    doesn't actually log anything.

    But sometimes this can be a problem because sometimes let's say that you

    are expecting to get an error but you're not going to be getting the like
    the error that you get when you first write it actually you get a different
    error for a different reason later and if you don't assert on the error
    that you actually got then you'll be in a bit of a bind and so you when you
    mock the implementation like that, you want to make.

    Sure that you are asserting that yes, this was called and we know what it

    was called with. So you want to insert what it's called with?The other side
    of this is let's say that you want to make sure that an error is not called
    because you're handling a situation where maybe react with typically error
    like for example when you unmounted component and a request finishes you
    want to make sure that there's no error about setting state on an unmounted
    component, for example.

    And so in that case, what I did just today was I set my error at or I I did

    spy on my error, but I did not want it to want to mock the implementation.
    I want to keep the original implementation.And then, I perform all my
    actions, whatever NI assert that the console error was not called.

    In this case, you do not want to unlock the implementation because if you

    do have an error you want to be able to see what that error was. So anyway,
    I thought that might be interesting. And in yeah, if you ever run into
    situations where you have a bunch of errors or logs or anything, just make
    sure you clean those up.

    So, they're not distracting from the output of the test. Hope that's

    interesting. Have a wonderful day.

    3 min
  • How to use TypeScript errors to guide your callbacks

    Your friends it's a beautiful day it's Monday and I wanted to share just

    something that I discovered while I was working on something just kind of
    an interesting workflow that I've come to start to use and that is if you
    are trying to use something and you don't know what type it requires rather
    than and assuming that it's written in touch script or at least has type
    definitions so like say you're passing a function to an API and some sort
    of callback, for example, maybe you're on an input in a j in your JSX and
    you have an on change in your not sure what type.

    The event should be or that first argument or you don't even know whether

    it accepts arguments or anything so the way that I do this is rather than
    opening up the docks and digging around and trying to find how this is to
    find out what I'm expected to do here you put in a function that you're
    pretty confident is going to break the types in some way and so for our
    input on change example, you can just put an inline function in there that
    takes a single argument that you type as null or something and then you're
    going to get an error and the error is going to give you.

    That the last line on the error is going to say that type such and such is

    not assignable to type null so in our example. I literally have this pulled
    up that's where this example came from but in our example it's type change
    event. HTML input event is not assignable to type null, so now you know
    that it's a type change event and if you're not sure where that change
    event is coming from then you can F12 into the unchange prop and it will
    take you right to where that is and here I see it's a type change event
    handler is what that type is and if we F12 into that we just keep on F1
    eventually we're going to.

    Find that this is typed as an event handler that accepts a change event

    input type or type as it's input ultimately this ends up just extending
    this synthetic event and it has one additional property a target
    interestingly that's an event target of the the given element so what was
    interesting about that actually is that that means that the target for a
    change event is equal to the input or to the current target.

    I'm guessing so that's interesting anyway, so yeah, that's just kind of a

    general tip if you.You're working with something you're not sure what at
    least for our function you're passing this function you're not sure what
    arguments it should take pass it something that's just bogus that you you
    don't know if it's right or you're pretty confident it's wrong and the
    error message should give you an idea of what you are actually supposed to
    do there and you can do the same with the return value as well so like
    return a symbol or something that you're confident will not be what you're
    supposed to return and you'll get an error message indicating to you or
    giving you an idea of what you should return hope that's useful and
    interesting have a wonderful day.

    3 min
  • Neural nets podcast recommendation

    https://youtu.be/gzq5AFCH5jk

    Hey, you're folks. So today I listened to a podcast interview. It's about

    50 minutes on. And it is on a podcast called Tesla daily. I which is a kind
    of interesting daily podcast about tests huh? But normally it's it's like a
    15 minute long thing, but this one was 50 minutes and it was an interview
    with this fellow by the name of well, it's not showing the full name here.

    James Duma and yeah, I,Don't I've never heard of this person before but

    they are really great at explaining neural nets and so I wanted to share
    this with you wanted to um, just encourage you to go give it a listen. Some
    of it was like hmm, I'm not sure I get this but after like thinking about
    it more and and listening carefully to that James explain it, um, I I feel
    like I have a much better understanding of neural nets now than I did
    before and I thought that you all find that to be kind of interesting, so
    I'm gonna include a link to theIt's on YouTube I I'm guessing this is also
    gonna be published as part of the the daily podcast that you can subscribe
    in your podcast reader or can whatever app that you use but I was really
    interesting kind of explaining how neural nets work especially in the like
    thinking about it from the context of Tesla and their autonomous driving
    they talk about that, but it's not specifically about that.

    There and there's a little bit of the history of neural nets as well. In

    here, so this person was very knowledgeable.And goes pretty deep
    technically. So I wouldn't listen to this one on three Xs I'm saying.
    Anyway, give this a listen it's kind of interesting and yeah. I think it's
    kind of fun to broaden your understanding.

    I know that I'm primarily a UI JavaScript kind of developer but yeah. I

    think that it's good to expand your horizons. So give this one a listen and
    I hope it does that for you. Okay, take care.

    3 min
  • When to use TypeScript's `never` type

    https://twitter.com/kentcdodds/status/1381453907730128900?s=20

    Hey friends So last night I tweeted this TypeScript question. When have you

    used never in a production codebase links to examples welcome? And I failed
    to mute the conversation and so I ended up waking up the next morning with
    tons of notifications, which was great. So many people were happy to share
    and I just wanted to share with you a couple or the like basic themes of
    the different examples that people shared.

    So the first is discriminating union. Oh and by the way, if you've never

    heard of never before the basic idea is it's a way for you to say.Hey the
    type script type checker as it's flowing through the types of my
    application, it should never be able to hit this type.

    So it's like those situations where you like this should never happen.

    That's basically when you use never. So anyway, the first is discriminating
    unions and a common example for this was if you had a component that could
    take a variety of different props. So an example is a component that could
    like draw a shape so you could be rectangle or a square or a circle and
    depending on the type of shape you want to draw you're going.

    To have different props And so square will have a width Rectangle will also

    have a height in addition to that. And then circle won't have either of
    those it'll have like a diameter something. So the you know, the
    discriminating union's use case for never would be when you union those
    props together you want to be able to say hey when it's a circle I never
    want to have a height or a width and when it it's a square.

    I never want to have a height because I just get it from the width and I

    never want to have a diameter because it's not a circle. In my
    mind,Actually most of the examples were similar to that and in my mind most
    of the time you're actually probably better off just making two separate
    components or yeah different components entirely that are responsible for
    doing that specific thing.

    However, sometimes there are definitely use cases for you know, if if

    you're going to provide me this prop, you also must provide me this prop,
    but if you provide this other one, then you must not provide this this
    other. So like aria described by versus already described stuff like that.

    So that was like the primary use case in addition.Switch out ifs and else

    statements this is where you can make a function that is basically they
    would call it a certain ever and it would return never it would throw an
    error. And basically your time typescript well by calling that function you
    get a type error.

    And so if you put this as the default case or something and you're not

    handling every case then type script is going to cause a problem for you.
    And then the last one was conditional types and that one still pretty hazy
    for me. I can't really explain it. So anyway, hopefully some of that was
    interesting.

    And I hope you have a wonderful day. Bye.

    3 min
  • Make the world better by doing this one simple thing

    Clickbait? Yes.

    Hey folks today, we're gonna go with the untraditional not tech related

    really podcast so I got my first dose of the modern of vaccine yesterday. I
    strongly advise that you do the same if you are able all of the data points
    to this being safe despite it how fast it was produced and everything so I
    if if you're not if you don't get the vaccine but you're able to then
    you're putting other people at more and greater risk unnecessarily so just
    please get the,Team let's get our lives back to as normal as we can so we
    can work on all the other terrible things that we need to work on and focus
    our energy on making the world a better place and yeah just for me this
    first dose has been this morning.

    I woke up feeling like I got hit in the in the arm really hard and so it

    felt kind of bruised and then I felt fine and right now I'm writing around
    on my one wheel so I I'm not super terrible but I am feeling a little achy
    and that sort of thing.

    I hear that the second dose is work.S and so we will see what we will see

    there but whatever issues I have it is worth the cost. I actually did have
    to test positive for the virus in October but yeah just getting vaccinated
    clearly. I guess this is affecting me anyway so so yes, I'm glad to be
    getting vaccinated.

    I'm hoping that we can return to our regular lives as soon as possible and

    I hope that you get yourself vaccinated too.And we can all just get back to
    a better situation than we are now all right that's all I had to share with
    you. I hope you have a glorious day it is beautiful here in Utah right now
    and it's just glorious so I hope your day is equally amazing and I wish you
    the best of luck in all of your personal and professional pursuits because
    yeah, sometimes we need a little luck so take care bye.

    3 min
  • Should every site be an installable PWA?

    Hey there friends, so I have a question somebody's asking on the KCD office

    hours channel in discord and I decided this is something that I can answer
    in the three minutes with Kent alright podcast, so the question is what are
    my thoughts on PWAs nowadays should all websites be PWAs are there const
    making your site's PWAs so in general or to be clear a PWA stands for
    progressive web application and normally when we're talking about this
    we're talking about something that can be like installed.

    You can have background notification like push notifications and stuff like

    that works offline, in fact Chrome recently started requiring or is going
    to require offline functionality to be present for your app to be
    installable as a PWA, so I have actually had my website installable as a
    PWA before and I've had a couple other a little apps or sites that I've
    made PWAs installable and it's kind of cool.

    I would caution people against just saying let's make everything a PWA

    because I have had some sad experiences with service workers with Gatsby in
    particular it was just so easy to turn on offline capabilities, which is a
    plug-in but unfortunately that plug-in had a dependency that had a funny
    problem with it and so I ended up having testing JavaScript.com install
    a,Service worker that would never get updated ever and so we launched
    testing JavaScript.com, it's like here's this is coming soon and then when
    it was officially launched a ton of people did not see the update and so
    they couldn't buy the course and it was just a total nightmare disaster.

    I had some frustration and annoyance with the PWA I had for my website and

    because people would come to see my blog and then I do an update between
    the last time they saw the flag and this time and so let's see old.Content
    and I'd have to do a notification that said hey there's some new content
    downloaded now and most the time people don't really care to have it
    offline and so it was just an annoyance so I would say that unless you're
    doing some offline support stuff then there's not really a great reason to
    make it installable and and whatever you have to have a good use case for
    your thing to actually be like an app and useful in that sort of context
    for making it a PWA, those are my thoughts on it.

    I hope that's useful in interesting take care.

    3 min
  • Why I no longer use newspaper code structure

    Hey there friends. So a while ago, I wrote well actually several years ago.

    I wrote a blog post called a newspaper code structure where I described the
    way that I like to structure my code to basically make it. I don't know
    easier for me to parse as I come into a new file and the idea is that
    anytime I have some sort of block of code that returns some value or
    whether that be a function or a module where your exporting values and
    stuff.

    I always,Like to do the the thing that it returns or the exports at the

    very top of the file and the reason for this is in a newspaper article and
    they make it they write it so that they add just kind of a high level first
    and then they slowly fill in with details and the reason they do that is so
    or at least maybe they used to do that this way is so that you could clip
    the article at any point to size it for where it needs to be and it would
    still be coherent to make sense.

    And in the same way I like to make my code so that it makes sense.Reading

    from the top down and if you need additional details then you can dive into
    the function there. And so what it ended up looking like is you'd have a
    function and like one of the first couple lines would be a return statement
    and then all of the guts of the function would be in a other functions that
    are below the return statement.

    This is actually like a thing that you can do. You can define functions

    below a return statement and they will get hoisted the declaration and the
    definition will get hoisted above the return statement. So it technically
    actually works. So I did.The first for a long time but I eventually stopped
    doing this and the reason is because I I was bothered that I couldn't put
    the exports and the return statement at the very very first at the very
    very top because any time like so the the hoisting functionality I'm
    talking about that works for function declarations, but it will not work
    for arrow functions, it won't work for variable declarations.

    So, I'd have to just put everything in enough function if I needed to use

    any variables and so what ended up happening.Was I'd have a couple of
    variables that I define at the top and then I never returned statement and
    then I'd have all the other functions or in a module I'd have you have to
    put all the import statements at the top.

    Well, you don't have to those get hoisted too but it just looks funny if

    you don't. So I put all those at the top and then I have some variable
    declarations and stuff and then my exports and so what I ended up with was
    a return statement and the exports that were just like in the middle of all
    the code.

    So now I just put everything at the bottom and it's easier to find. So,

    that's that's why I made that change. This is an answer to somebody in
    Discord. I hope you're having a great day. Bye.

    3 min