3 Minutes with Kent

3 Minutes with Kent

By Kent C. DoddsTechnology
Download on the App Store

All 3 Minutes with Kent episodes

  • Using patch-package to workaround a create-react-app issue

    Hey friends. So today I was working on a little problem that I had with

    Create React app. So if you don't know Epic React is a combination of a
    bunch of React workshops that I have given many times in a life setting and
    it's a recorded version of kind of a live workshop that's kind of the feel.

    Anyway, all of the workshops there are powered by create react app under

    the hood and I've got a abstraction on top of that to share a bunch of code
    between all these different workshops.So I am in the process of moving
    everything over to TypeScript and I want to be able to have two different
    versions of TypeScript or of texture configuration for the exercises versus
    the final version.

    So I want to make sure that as we're moving everything over to TypeScript

    if you don't want to do TypeScript, it's as like easy as possible or if
    you've got very limited experience or no experience with TypeScript, you
    should still be able to get a lot of out of the workshops without having to
    have a bunch of red squigglies all over the place with their messages that
    you don't understand.

    And so,I don't want to have strict mode on of course for the those

    exercises because that would be against that goal. But I do want to have
    strict mode on for the final version of all the the exercises so I you
    know, because there's good reason to have strict mode and and it kind of
    helps me as I'm working on it to make sure that I'm doing everything the
    way that you probably should in a real application.

    And so, unfortunately with Korea react app if you don't have the TS config

    set up proper well here let me back up so.You can do this by having using
    project references and so you have just your main TS config that references
    other TS configs and then those can include an exclude different files.

    So I can get that set up but the problem is that in create react app if

    you're root TS config isn't doesn't have all the right properties then it
    will fill those in automatically for you and that messes up the references
    stuff. So, it just doesn't support references which is a big bummer.

    I made an issue about this. But what I did for,The foreseeable future

    unless create react to app ad support for references is I used this package
    on NPM called Patch Package and it allows you to install all of your
    dependencies and then you make a change to one of the files in your node
    modules and then you run the script and it will generate a patch for you
    and then you just set a post-install script in your package JSON and it
    will after your people install it it will apply that patch.

    And so, I was able to make a small change to create react app to support

    this. So give patch package a look it's pretty cool. It's kind of
    interesting. IHope that was interesting to you and I'll talk to you later.

    3 min
  • esbuild is a FAST bundler ⚡

    Hey folks, so today I want to tell you about ES. Build so if you haven't

    heard of ES. Build it's been making a lot of noise recently. I think it's I
    I didn't check but I think it's been around for at least a year. I think is
    the first time I heard of it.

    But basically, it is kind of you you can think of it as a bundler like

    webpack but written and go and apparently go as much better suited for
    bundler tasks because it is wicked fast. Like I've tried it myself and you
    think that it's broken.Because it's so fast like you think it just didn't
    run and because you execute ES build and it's instantly done.

    It's it's outrageously cool. And so it's starting to take over I've noticed

    in lots of different areas like the new meta frameworks that I'm seeing are
    using ES build bite the the view meta framework tool. I think it's like
    gonna be the new view CLI or something eventually but it's powered by ES
    build Remix, they're currently working on moving over to ES build.

    I I'm using ES Build in MDX Bundler and a couple of the like newer smaller

    things like from Jason Miller the creator of Preact he's using ES build for
    his thing WMR or something. I think is what is called um, but yeah, it's
    just like oh and there's a new testing firmware called UVU that is using
    ES.

    Build under the hood to just be just outrageously fast. For compiling

    typescript and everything. The only downside to using ES build currently
    that I can see is there's,No support for custom babble plugins which is a
    shame but these days I don't really use custom babble plugins for anything
    other than like code transformations like like code gen or prevalent and
    these are macros and I'm thinking we may be able to make a macros sort of
    plug-in thing that works with ES build.

    So that's that's something I still need to investigate but and I think some

    people have tried some experiments to make Babel work with the US build but
    when you start doing that stuff, you kind of negate all of the benefits.The
    performance benefits of ease build because then you have to do AST
    compilation in node again and yeah that can be slow.

    So anyway, if you haven't looked into ES build yet. I'm not telling you

    that you need to take your work application and and migrate everything from
    webpack over to ES build, but it is pretty powerful and it's something to
    keep an eye out for and there are other things.

    I think there was one like SWC or something like that, that's written in

    rest. But yeah, it's exciting times and I thought I'd just share that with
    you. Hope you have an awesome day. We'll,Talk to you later.

    3 min
  • Getting a Native ESM module imported into a CommonJS module

    Hey friends So today. I just want to mention something that I've been

    working on for the last couple days. So if you didn't know node version 10
    is the last version of node that so does not support native ECMAScript
    modules without a flag. So you can use ECMAScript modules with node version
    10, but you need to pass it a flag version 12 and above I'll do not require
    a flag they just support a native ESM out of the box.

    And what's exciting about this is it means that package authors can start

    using native ES module.'s and and we can consume them as native modules and
    we don't have to compile down or compile away those ES modules. This is a
    good thing but it also comes with a fair number of complications.

    For one thing we're not there are interesting semantics with the way that

    ESM works native ESM. For example, you cannot use require for a native ES
    module. So, you can't just require a library or another module that you've
    written. You.Have to use an import statement. Now, you're probably working
    in if you're working in a node application, you're probably working in one
    that is not using native ESM if you if you are using native that's awesome
    good for you, but most of us probably aren't.

    So we're either compiling our import statements to require or we're

    requiring writing require ourselves. And so if you want to start using
    packages that are built with native ESM, then you're going to need to do
    things a little bit differently. So you.Can't use an import statement in a
    common JS module.

    So a non-ESM module. And so the only way to get a ESM module into your

    common JS module is by using a dynamic import statement, which looks like a
    function when you call import. It's an asynchronous operation, so you need
    to use asynchle weight. Luckily for us node version, or yeah recently at
    some point.

    I think version 14, we know have support for root or or module async await.

    Unfortunately,That only works in native ESM modules So if you want to use a
    if you're writing a common JS module and you want to import a ESM module
    the only way to do it is to use a dynamic import and you have to it's
    asynch weight and so or or promise I guess.

    And so, you have to write an async function to be able to import anything

    from ESM. There's I'm going to need to like write a blog post about this
    and stuff because there are a couple of interesting things here. It's going
    to be a little bit painful, but I think in the end we're all going to be
    much.

    Better off just going full native ESM. I hope that's interesting. Bye.

    3 min
  • When is a good time to buy a stock?

    Hey friends So today I'm going to talk about investing. And so, let's just

    like close your eyes maybe and imagine with me a graph of the stock price
    of any stock. Typically, it's going to have some ups and downs and things
    and let's say that the point at the end is at a certain level.

    And I want you to imagine or to answer me the question. When would have

    been like thinking historically, when would have been a good time to buy
    the stock. And in your mind, you might be looking at some of the dips in
    the price of this stock.You and you might be thinking oh like very at the
    very beginning it would have been really good to buy the stock.

    The answer that question is actually any point where the stock price is

    less than you think it's going to be in the future. That's the answer to
    this question. So when is it a good time to buy a stock? It's when you
    think the stock price is less than it is going to be in the future.

    So the best time or a good time to buy this stock, you know, of course the

    best time to buy the stock would be at the very beginning, you know of any
    successful company the the very initial offering or whatever.But barring
    that when's a good time to buy the stock it's just any time you think that
    the price is lower than it's going to be in the future.

    So, I think a lot of people make the mistake of looking at a stock price

    and be like, oh there's the dip that would have been an awesome time to buy
    the stock. Yeah probably but I mean when when you're talking about
    investing there there are two types of quote-unquote investors.

    There's the investor that's doing high frequency trading and they're day

    trading they're looking at stock and hoping that it's going to go up in the
    next couple days, so they can sell or whatever.This isn't an investor. This
    is a gambler. And Gamblers they can make some they can lose some but they
    spend their lives just stressed over stock.

    The other kind of investors an actual investor the person who researches a

    company has a good idea of what that company has to offer and what it's
    potential is and invest in that company for the long term. This is a type
    of investor that I am and I am I focus on a few select positions, so I
    companies that I think are going to do.

    Really well in the future whether or not the stock is overpriced right now

    is totally irrelevant all in concern about is will that stock price go up.
    And and yeah, so don't worry about like stock prices going up and down. I'm
    just focus on is the the stock price lower than it's going to be in the
    future based on the research that I've done.

    So I know that's not at all tech related but it was just something that I

    was thinking about I this is not investment advice whatever all that
    disclosure stuff but it's just kind of my,Thought process around investing.
    Hope that's useful. Have a wonderful day.

    3 min
  • Don't sell your kindness for time

    Hey friends so I was waiting in line for something and I needed to get this

    thing done so I can move on to my next thing so I wouldn't be late and
    whatever and there was just this big group of people in front of me that
    they were just taking a long time and they should have come earlier to do
    the thing that they were doing because they were gonna be late for what
    they were doing to and and so it was a little bit frustrating to me and I
    was part of me wanted to like say something I got or like can I cut in
    front of you because you know, I just,I'm mine's really quick or whatever
    but I realized that you know, I wanted to assert myself and be rude to
    generate like basically to save myself a few minutes it really wasn't a lot
    of time and it made me ponder a little bit on how how much time are you
    willing to give to a like to be rude and how much time does it take before
    you decide that it's better to be rude?

    I'm now there of course sometimes where it like you, you know, you're it's

    spouses having a baby or something like they're you need to hurry up
    whatever but in general I think that it's just better to learn to be
    patient like if it's really just a matter of a few minutes and maybe you're
    gonna be a little bit late to a lunch or or some meeting or something, you
    know, is it really worth being rude or maybe cutting somebody off of
    driving unsafely or whatever just to save yourself a few minutes or be less
    late, you know, I,I that was just something that I was thinking about and I
    realized that typically I share on this three-minute podcast some of my
    thoughts on software development and the career thereof and whatever but I
    one of the things that I think is really important and actually was the
    first episode of three minutes with Kent was how important it is to be kind
    so you know is it my father-in-law I like to quote him saying is it more
    important to be a hard worker or to be smart and it's more important to be
    a hard worker and isn't more important to be a hard worker to be nice it's
    more important.

    To be nice and I feel like that's a general principle that we should

    explore and a little bit in our lives and and try to emphasize being kind
    to other people. I have this laptop sticker on my laptop. I I'm very fond
    of stickers and I saw this on a youtubers laptop and I just had to find it
    and get it and so I did and it's actually it's a circle and it has Fred
    Rogers mr Rogers in there and it says the words be kind and I actually got
    two of them so that when I get my next laptop I make sure I have another
    one.

    Of those I love it anyway. I hope that's helpful and interesting have a

    wonderfully.

    3 min
  • Don't Trick TypeScript

    Hey friends So today I was writing a blog post as I often do and I wanted

    to ask a question of some TypeScript folks always in the Tit script
    community and my question sparked a long discussion kind of argument
    between people about whether a assertion function is tricking the compiler
    if you're not throwing an error in the function.

    So let me explain I actually recently wrote a blog post about the different

    function syntaxes that you have in TypeScript and one of the things that
    you can do is make an assertion.Function and basically what that does is
    you say, hey type script this function asserts that the given argument is
    of a certain type.

    And so therefore you can do some type narrowing by calling that function.

    So say you've got a an array and you want to filter out anything that's not
    a number then you can write a filter function that asserts that things are
    or maybe rather not filtering out a number but you want to make sure that
    everything's a number and so if one of them isn't a number then you want to
    throw an error or something like that.

    And so you can make a function that asserts that it's input is a number and

    if it's not then that won't be accepted and so what some people are arguing
    is it's totally fine to not actually throughout the error and just make an
    assertion function that that says that the types cannot be anything but a
    number.

    But this one an individual is saying no that's tricking the compiler you

    need to make sure that you actually do throw an error if the type is not a
    number. So my opinion is I agree with that. I think that you should not be
    doing things with theCompiler that are basically saying hey type script my
    code does this but your code doesn't actually do that.

    You're just tricking the compiler into thinking that your code does that so

    that you can make the compiler do what you want it to do. So basically, I
    want to make sure that the code that I end up shipping to the browser
    operates in the way that I'm telling TypeScript it's going to operate and
    if you're so like if you trust so much the compiler to make sure that your
    types are all correct and everything then you shouldn't ever run into the
    situation.

    When you actually do throw because your type should be correct But if

    something weird happens, then you actually do want to have that that error
    thrown because unexpected things could happen down the line which could
    make things even worse. So I would really recommend that you don't try to
    trick the compiler when you tell type script a thing as of a certain type
    it better be of that type when you're making an assertion function, you
    better be doing some assertions.

    I think that's important though. Anyway, I hope that's interesting. Have a

    wonderful awesome typescript.

    3 min
  • How to solve programming problems

    Hey friends so today is office hour stay and I am answered a question on

    office hours that I thought I'd share with you and it's from Salem and the
    question was hey can't can you walk us through the process for when you get
    stuck on a problem and what I do is I try to find where the problem is.

    I don't try to just do a bunch of random things and hope that one of them

    works or the solves a bug or whatever because what can happen is, you can
    implement the wrong solution in the right place and and move the problem
    andSo that you like you haven't actually saw the problem you just moved it
    somewhere else and now you think that you've solved the problem but you're
    gonna hear about this in the future and or like you might implement
    something wrong and and somebody else can create this problem all over
    again, so you need to understand why the problem exists as well as how you
    can avoid it in the future and then it can actually help to have a test in
    place to make sure that the problem doesn't show up again, so one thing
    that can be helpful is to write a test that that reproduces the problem
    first because that way like,You just have a much better iteration cycle on
    did I fix it no or yes or whatever but another really critical piece of
    this is to isolate that problem so remove as much as you can and the best
    way to do this is to reproduce it in a small isolated example, so try to
    take it outside of your app just install the dependencies that you know,
    you need or whatever bring in the code that you know, you need and
    reproduce it in that small example sometimes that's possible sometimes it's
    not but that's the best possible thing.

    That you can do is to just remove as much as you can in a completely

    isolated example sometimes it's a very difficult so if you can't then the
    next best thing is to take your existing app where you're experiencing the
    problem and remove pieces of code until ultimately eventually you'll wind
    up with nothing on the page except the component that's giving you the
    headache or whatever the case may be or you're running only a single file
    on node that is causing the problem and and that can help you isolate the
    problem sometimes that's difficult and so especially when you're talking
    about like async stuff rate.

    Conditions or whatever console logs can be really helpful in in those

    situations but yeah really finding where the problem is and if it's a
    regression then finding which commit caused the regression can also be
    quite helpful so doing a get bisect whether using the command or just doing
    it kind of by hand can also be really helpful in isolating the problem, so
    hopefully all that is helpful good luck to you in dealing with these types
    of problems, it's no fun, but I know you can do it have a great day.

    3 min
  • Make Processes Instead of Goals

    Hey friends, so I want to talk about making processes not goals. So I

    noticed recently that I cannot stretch as much as I used to so I could try
    to put my hands down and try and touch my toes and I'm not even close and
    and and bothers me and I'd like to be able to be more flexible and my
    muscles are sore and stuff.

    So I want to do more stretching. But I I have you know lived life for long

    enough and and made enough goals to realize that making goals with an end
    in themselves.Especially like big Harry audacious goals are it's it's
    difficult and and there's nothing wrong with setting your sights high on
    something that you want, but it can be overwhelming and often it leads me
    to just kind of giving up or just saying oh not today, like I'm having an
    off day or something.

    But if instead if I focus on the process rather than the specific outcome,

    then it's a lot more straightforward. It's a lot easier. We often talk
    about like taking a big goal and making smaller goal.S but I think that if
    you can take a big goal something that you want to have accomplished like I
    want to have a job or I want you know, and often some of these goals are
    things that you can't make happen yourself like it depends on other people
    but anyway you take one of these big goals and you figure out a process
    that will get you to that goal.

    So if you do a codecata every day, or if you do, you know, whatever it is,

    just like find something that you can do. So for me, I have this notebook
    that I keep in my pocket of all the things that I do or that I want to get
    done in the day.

    And I look at it regularly throughout the day to remind myself of what I'm

    trying to accomplish for the day. And I put on their stretch and so every
    time I pull out my list I see stretching away. Oh, yeah, I need to stretch
    and so I'll just do a stretch for a couple minute or for, you know, a
    couple seconds like 30 seconds.

    And I do that throughout the day and and this can become a process for me

    where ultimately by following the process and trusting in the process. I
    will have my ultimate goal, which is to be able to to stretch and feel
    comfortable andYeah and just not feel so tight all the time.

    So anyway, I hope that's useful to you think about the like really big

    thing that you want to accomplish and instead of just thinking about it
    every single day and like I need to do things to get me there. Think about
    the process. Think about something that you can do that is simple that you
    can just make a regular thing that will ultimately get you to where you
    want to be.

    I hope that's useful. Have a wonderful day.

    3 min
  • You Can Use React EVERYWHERE: Custom React renderers

    https://github.com/chentsulin/awesome-react-renderer

    Hey friends So today I want to tell you about this repo I found called

    Awesome React Renderer and I'll add a link to it in the notes here, but you
    know how you have the reactant module and then you have react on and then
    you have react native. Well, these are called renderers so react is
    responsible for creating the elements and stuff.

    And then these different renderers are responsible for taking those

    elements when things are supposed to be rendered and showing it up in
    whatever environment that it's in whether that be in the web or if it's on
    an aided device or whereverWell it turns out that because of this plugal
    went nature people are able to innovate and do some really cool things with
    react and this repo lists a bunch of different custom renderers that people
    have built.

    So you've got React dominant here, but you also have react to tiny dom

    which is a minimal implementation of React on using React Reconcilary,
    which is interesting. I'm not sure I'd recommend using it in production,
    but maybe there's yeah, there's tons of stuff in here you've got React Art
    React Canvas for rendering in Canvas popular one that you may be aware of.

    Is react three fiber, which is for rendering to three JS so you can get

    some really awesome 3D stuff going on in the web, which I just think is so
    so cool. You may have heard of React to Native Dom which is supposed to
    allow you to have the same code run in the web as well as in native ends up
    being pretty cool.

    I know a lot of people have used that. There's a reactive VR which is cool

    and that is actually like an official. React renderer for virtual
    reality.And then you also have desktop renderers So I'm just looking at the
    list and reading a couple of the interesting ones So we've got this proton
    native which is a reactive environment for cross-platform native desktop
    apps and you got a bunch of others here, we've got react native of course
    for mobile.

    There's also a reactant native script and then command line interfaces

    we've got three of these react blessed and ink and react CLI I think I've
    heard a lot of good things about React blessed and ink before. So yeah, you
    can like render stuff to the terminal and have like kind of a UI in that
    terminal along with your seat.

    Belies Very cool There's React TV for television There's React hardware, so

    you can interact with like maybe making hardware applications. It's just
    mind-blowing. There's one for email. There's one for working with PDFs and
    Word documents and stuff. There's one for music called Wax, which is kind
    of interesting. So anyway, there's just a ton of React Figma is in here.

    You've got React Slack renderer and there was one that's a React AST, which

    is like mind-blowing very very interesting stuff. So definitely come take a
    look at this. It's fascinating what you can do.With React these days. I
    love it. Take care.

    3 min
  • Doesn't matter how slow something is if you can cache it before the user

    So I've been working with Remax for a little while and I'm still trying to

    learn enough about it that I can articulate my feelings on it really well
    because I know a lot of people are comparing it to next year yes and and
    likewise should I pay for something when there's a free option?

    Trust me, this is gonna be huge and I'm super excited for when they do

    things to make it so people can try it out a little bit more. But as I was
    working with it, I,Am or just over the last few months that I've been
    working with it it embraces browser-level caching and CDN caching so
    naturally that this becomes really nice.

    So when we're talking about like resources that can be cached heavily

    regardless of the user even with the user honestly like with user data one
    of the nice things about that sort of caching strategy is it means that?You
    can not be lazy but be more ambitious with the sorts of performance things
    that you're doing on the server.

    And so like, for example, I had I'm able to have my blogs be built and

    calculated or like compiled from MDX on the fly because I know that the
    like things are going to be cash and no users actually going to have to
    wait for the time that it takes to compile on the flying.

    And yeah, so it's really,Awesome that way like we don't have to worry about

    building ahead of time we can update the blog post and then have it
    immediately update the cache and and and no users have to wait or anything.
    There's actually a really great video that Ryan Florence put together on
    the remix channel on YouTube talking about caching and you should
    definitely go look that up but being able to just say I'm gonna do this
    performance intensive thing or maybe not even like perform or like
    computationally expensive butWe have to like hit the network and go get
    this and whatever, I don't care how long it takes because none of my users
    is gonna feel that I'm going to hit it first as part of my build problem or
    part of my deployment process or my cash invalidation strategy and so I'll
    hit it first.

    I'll make sure that the cash is updated before any users even and know that

    the cash risk changed. I'm really looking forward to being able to actually
    demo some of this stuff. Remix is amazing. I can't wait for you all to see
    this stuff that I'm thinking about doing with my web.

    Site with it. It's gonna be awesome. Okay, hope that's useful in

    interesting have a wonderful day.

    3 min