21: Delete Your Components with Kent C. Dodds
Chantastic talks with Kent C. Dodds about his adventures in React development and why we should be optimizing code for delete-ability. They discuss React Rally, managing your career, taming your ego, keeping healthy and happy on Twitter, tools for composing components well and when to use them, and what’s next for React.
Featuring
Links
- downshift — 🏎 Primitive to build simple, flexible, WAI-ARIA compliant enhanced input React components
- Compound Components — Ryan's Phoenix ReactJS talk on compound components
- glamorous — 💄 Maintainable CSS with React
- CodeSandbox
- Prop Collections — How to give rendering control to users with prop getters
- Simply React — Kent's 2018 React Rally talk on compound components and composition
- react-redocx
- mdx-deck
- Brent Jackson
- Adam Morse
- Sunil Pai
- Sarah Drasner
- Marcy Sutton
- Nitin Tulswani
- Shawn Wang
- Ryan Florence
Transcript
[00:00:06] Sponsor: This episode of React Podcast is brought to you by ReactTraining.com. In-person, hands-on training for development teams from React community leaders and experts. Visit ReactTraining.com to learn more.
[00:00:25] Michael Chan: This is React Podcast, and today I have an incredibly special guest, the prolific Kent C. Dodds. Kent is one of the most prolific JavaScript developers I know. He is all over the place. He um is a software engineer at PayPal on uh TC39. He has courses on Egghead and Frontend Masters, always putting out awesome libraries and talking about his experience. So it's a real honor to have him. Um Kent, how are you doing today?
[00:00:54] Kent C. Dodds: Oh wow, I'm feeling like embarrassed or like bashful for that really nice intro. Thank you so much, Michael. Um, yeah, doing doing great. Um, really happy to be here at React Rally 2018. Um, yeah, I've come every year. It's my favorite conference, so I'm happy to be here.
[00:01:12] Michael Chan: It's a fun vibe here, isn't it?
[00:01:14] Kent C. Dodds: Totally, totally. They give you plenty of time to to chat with people, which is the reason you go to a conference.
[00:01:21] Michael Chan: Yes.
[00:01:21] Kent C. Dodds: You get the the talks and stuff on YouTube, And and so everybody appreciates that, but the reason we go to the conference is so we can be there and meet people. And React Rally gives you 2 hours for lunch and gives you money to just go out to a restaurant somewhere with people and and big breaks. So yeah, I I just love that about React Rally.
[00:01:40] Michael Chan: Yeah, all those things seem to culminate in a really awesome audience um experience as well. Um so all the, at least as far as I've noticed, um the speakers kind of get up and they're like a little bit nervous, you know, like every time you kind of get up and you're feeling a little bit exposed, but every time, every talk so far, um everyone in the audience has just been so eager to meet those people and like laughing at the jokes, kind of high-fiving and hollering and applauding at all the right places. It's just such a great conference to be at.
[00:02:11] Kent C. Dodds: Yeah, it totally is. And and I just huge props to Jamison Dance and and Matt Zabriskie for all the work they put into it. And and I know they they have a lot of help from Sunny and her team. Um they do just um put out amazing conferences, so yeah, huge props to them, no pun intended.
[00:02:28] Michael Chan: So I wanted to ask you, um before we talk about some of your your work and your classes and what you're helping people understand in the JavaScript community, how did you get into programming?
[00:02:40] Kent C. Dodds: Oh, that's a that was an unexpected question, but I'm glad you asked. It's kind of a fun story. So, um I'll try to keep it brief. I can I can ramble, so feel free to interrupt me. Um so when I was a kid, I I never really was like into the computers thing beyond video games. I think that's pretty common. But uh my friend was like way into programming and stuff, and he tried to teach me, and I just remember him trying to explain a number, and I was like, okay, I get a number. And then he was explaining a boolean, and I was like, oh, if you say so. And then and then he tried to explain a string to me, and I just, I was totally lost. I was like, yeah, this programming thing is your thing, and I can appreciate you for who you are, but that's not me. And then eventually I went to school, went into electrical engineering, thinking I wanted to do whatever I wanted. And my brother did that and he gets to do what he wants. So I was like, okay, yeah, computers are cool. Uh, that didn't work out very well for me. And eventually- and to do that, I had to take 2 programming classes. And I did okay, but I hated it. I was like, this is the worst. Like, why would anybody want to sit in front of a computer? And I think part of the reason that I didn't enjoy, it was our uh the TAs, the teaching assistants, um convinced everybody to try to use Vim as their editor.
[00:03:55] Michael Chan: Oh, that's a terrible way to start.
[00:03:57] Kent C. Dodds: Right? Yeah, like I'm writing Java and C in Vim. Like, yeah, that doesn't that was not fun at all. Um, so I'm like, I can't even quit this editor. Like, why would I want to?
[00:04:07] Michael Chan: It's like learning to ride a bike in clogs.
[00:04:09] Kent C. Dodds: Yeah, yeah, it is. Uh, oh yeah, so it was- that's great, thanks Michael. Um, yeah, so I I didn't really enjoy it, but eventually found my way into information systems, um, took another programming class, and at the time I had an internship, um, where I was required to do some like, uh, monkey work stuff that was really boring. And I was in that programming class and I was like not excited about that because I I knew I was not a programmer.
[00:04:38] Michael Chan: Yeah.
[00:04:39] Kent C. Dodds: But um I was doing this monkey work, and I didn't like monkey work either. So I started automating some of my monkey work with programming. And that's when it all took off for me. I was like, wait, so practical application. I'm not just doing linked lists now, I'm actually like doing something useful. Um and so, a hop, skip, and a jump to discovering JavaScript, and then I really got excited about programming.
[00:05:00] Michael Chan: Yeah, so you were kind of hooked by the fact that you could optimize the repetitive tasks.
[00:05:04] Kent C. Dodds: Yeah, yeah, like solve solve problems I was having. Using uh using programming. Um I I could turn myself into a thousand Kents using using code, and I thought that was pretty cool.
[00:05:17] Michael Chan: A little army of Kents.
[00:05:18] Kent C. Dodds: Yeah, yeah, exactly. Little Kent interns doing all this stuff for me.
[00:05:22] Michael Chan: That's awesome. So what inspires you to um to share your work and do all of the training work that you're doing these days?
[00:05:31] Kent C. Dodds: Oh, that's a great question, Michael. So I um I feel like it's really important for people to recognize um where their um where the blessings in your life come from, um and the privilege that we all inherently have. Everybody is privileged at one level or another. And I um like I grew up in a stable family. I didn't ever wonder where my next meal was coming from. And so I had a childhood where I could learn and grow in a really nice and healthy environment. I went to a really nice school that was supported by my family as well. And so, like, so many things I didn't have to worry about so that I could get to where I am now. And so I feel like I have a moral imperative to help other people who are uh who didn't have it as easy.
[00:06:24] Michael Chan: Yeah.
[00:06:25] Kent C. Dodds: And so that's that's the biggest motivation for me. Um, and so that's and that's why so much of the stuff that I do, I try to make as accessible as possible. So all my workshop material is open source. Often I'll record my workshops and make it available on YouTube for free. And um it's just because um the the people who can pay and and who can support me, I appreciate them and they will. Um and so I don't I'm not worried about sharing the stuff that I know for free because I know it's it's helping the people who can't. Yeah. Who can't pay. And so I'm I'm glad to do that. Um it's also just like a blast and a half. It's so fun to um to talk to people who say that what I've created has helped them in some way. Uh there's probably a little bit of ego And I'm trying to trying to get a handle on my own ego a little bit. Make sure that I I put my value where it should be. It's
[00:07:15] Michael Chan: hard. You see that Twitter Twitter Twitter account go up. You see the email list go up. And it's kind of hard to not think that like I'm pretty awesome.
[00:07:22] Kent C. Dodds: Yeah, it is. It is hard. And there's nothing wrong with with getting a following. Like it's it's part of my career. Yeah. You know, it's it's an important part of of that. Um, but yeah, I have been like recently really focusing my um mental brain power on how can I make sure that I'm putting my self-worth in things that I can control and things that actually are like healthy for me to feel good about. Um, you know, 'cause if if um something wild happens, React goes out of favor, or I like something terrible happens, um I don't wanna feel like a failure failure of a human being. Yeah. Um when something that may have been out of my control happens. So, yeah, it's I and I think a lot of people, uh I would encourage a lot of people to really um get introspective about themselves and and where they are feeling feeling their worth, because you don't want somebody telling you that they don't like you to ruin your day. And for a long time, that's that's been me. So, um, yeah, so it's it's a constant constant effort, but I'm I'm glad to help the people that I do. Um, and it's a lot of fun.
[00:08:27] Michael Chan: We talked with uh Ken a few weeks back, and he was saying what a weird transition that is, especially in open source and programming right now, where you put something out in the wild and you don't really think much about it. Like when you're starting, you're just gonna put it out there and then maybe it gets successful or, and then people start following you on Twitter and all this stuff. And it feels really great until people start hating you on Twitter and like filing these issues telling you what an idiot you are for using this pattern or doing something in a non-performant way or whatever. And so I think that's really valuable what you're saying, to be introspective about how you're feeling about things and accept those good parts of that and realize that there's gonna be bad parts that come along with that, but realize that none of that is you as a person, right? And if someone doesn't like what you're putting out into the world, like, that's not- that's not a bad on you. Like, you're still- you can still be like whole and happy even if there's people that aren't in the Kent C. Dodds camp.
[00:09:26] Kent C. Dodds: Yeah, yeah, totally. And I, um, I've learned over the years of open source that I, I've been in things, like I've been pretty fortunate to not get a lot of hate mail or anything, but I've definitely gotten a little bit. And um earlier on it was like they're slighting my honor or something like that. And and it but it wasn't, I like I wouldn't get mad at them, I would feel bad about myself.
[00:09:49] Michael Chan: Sure, yeah.
[00:09:50] Kent C. Dodds: And um maybe I'm a little bit mad at them. But uh I yeah, so it just really impacted, like 'cause 'cause I am my code, right? Like that was the attitude that I had. And so getting yourself out of that is um a really important part of of your own mental health. And now, like, it used to be that somebody would file an issue and I'd respond like instantly and say, "Time me, I'll get this released in 5 minutes." This happened once and and then I released it and it was 7 minutes and I was like, "Oh, sorry, I didn't like fix that bug in 5 minutes." And I felt so cool about myself. It wasn't and it wasn't I think it was a feature, it wasn't a bug. It was a feature that somebody else needed, I didn't need. Sure. And so, um, I've Uh, I found that that's a really awesome path to burnout.
[00:10:33] Michael Chan: Yeah.
[00:10:34] Kent C. Dodds: And so I've I've found a way around burnout, and that's basically if I don't want to do it or I don't need to do it, then I won't do it. And um, and so like I have open issues on my projects like all over the place that are just like, uh, I just add a label help wanted, and I sometimes I don't respond. And I I feel bad about that, but I like people have to understand I I get dozens and like, like at least 50 questions or issues or like Twitter DMs a day.
[00:11:03] Michael Chan: Yeah.
[00:11:03] Kent C. Dodds: And so I, you have to kind of figure out how to optimize for uh your own happiness first and then, um, you know, serving other people as well. So, often, like if it's a project I'm interested in, then I'll continue to to do things I don't need because it's something I want to do. But if I start losing interest in the project, um, then like I'm I'm definitely, another aspect of this is making it um really easy to contribute to and and then giving ownership as well. Um because the people who are who are using the project um should be the ones building it too. Um and so, yeah, so like there's that side of it as well, um of of being like really free and open with the contributor rights. But yeah, that's been really helpful to me. It's just like I only do the stuff I want to do or need to do for work or something, and I don't don't do anything else. And then that's kind of how I avoid burnout. It's worked out pretty well.
[00:11:54] Michael Chan: Good. You have to decide where your time is best spent too, because as someone who wants to make sure that um people have the tools they need to progress in their careers, their understanding of things, um maybe fixing that issue isn't your best time spent, and you can help a lot more people if you do uh if you do something else.
[00:12:12] Kent C. Dodds: That's very true, yeah. Like I'll I'll get uh Twitter DMs um on a regular basis, like, here's a question, and I'll normally I'll direct them to my AMA, because that's a public forum where I can answer their question and and help a lot more people. So that that's worked out really well, or sometimes I just I won't be able to respond, because yeah, that you do have to prioritize. Another thing with that is finding ways to increase the impact of solving their problem. So early on in open source, I would they'd say, I have this use case, and I'd add a part to the API for that use case. Mm-hm. Had a lot of like single use case API features on a lot of things, and recently, And maybe this is a good segue into what we're gonna talk about, but uh recently I've been um taking a step back and thinking, what's the broader use case, um or or what's something that I could do to kind of invert control or or um just give more flexibility and power so that I can they can solve this use case, but also solve a whole myriad of others so that I never I don't get the issues, they the problems are already solved.
[00:13:18] Michael Chan: Yeah.
[00:13:18] Kent C. Dodds: Um and that's that's actually worked out really well for me uh recently.
[00:13:22] Michael Chan: So I saw a lot of you're exploring these concepts, um, you kind of explored out in the open, uh, as you were, um, creating Downshift, which is, um, at a high level, kind of a dropdown library, right, for React.
[00:13:36] Kent C. Dodds: Autocomplete. Like, I think I call them enhanced inputs. Okay. Yeah,
[00:13:41] Michael Chan: yeah. Okay. Um, so this is, this is where a lot of your work had started in this kind of, um, idea of uh React component composition and um how to, like you said, invert control, allow people to compose their own piece, own things together from these much smaller kind of single responsibility um components. Um can you talk about, you know, the experience that you had and like the things that you learned throughout that process?
[00:14:08] Kent C. Dodds: Yeah, thanks for asking, uh because this is, this gives me a great opportunity to, uh um to thank people who helped in the creation of of Downshift. So um I coded it myself mostly, um and I actually I livestreamed coding it too. So people can, people can watch in two parts the, uh, it was like two days worth of, of coding all day, pretty much, um, of me getting to the, what is the final version of, of Downshift. And since then it's been, uh, subtle, uh, features and things, um, to handle use cases. Um, so yeah, but the, the process of creating it, I, uh, or the motivation originally was, um, we had this We had 3 implementations of autocomplete or or um auto-select, uh whatever, in our app.
[00:14:55] Michael Chan: Some type of form element.
[00:14:57] Kent C. Dodds: Yeah, yeah, for uh enhanced input where you type and a dropdown comes and it filters and you can click on one or or select one. Uh so we had a country selector, recipient selector, um and a and then another recipient selector that was styled differently. So it had to be completely different implementation altogether.
[00:15:14] Michael Chan: And this is at PayPal?
[00:15:15] Kent C. Dodds: At PayPal, yeah, in one in one repository.
[00:15:17] Michael Chan: Okay.
[00:15:18] Kent C. Dodds: And I'm sure like there are dozens of other re-implementations of the same thing in other other repos. Um and and some of these were like open source projects that we forked, that somebody forked, wasn't wasn't me, but like forked it internally and and uh uh just committed it uh to to the codebase and made alterations. So um I was tasked with taking our country selector and adding it to another page um that was technically in a separate app, just in the same repo. And, um, I found it to be really difficult because the, um, it was coded so specifically to where it was. Mm-hmm. Um, and so I was like, this, like, this is the worst. I, we, we already have 3 implementations of autocomplete. I'm thinking about making another one, uh, just for this. I'm going to make the end-all be-all autocomplete that just works for every, everything. And I, before I built it, I, I looked around at other, um, solutions. And thought like maybe we could retrofit some of these, make our own that uses one of these under the hood. And none of them were flexible enough for my use cases, my varied use cases. So-
[00:16:22] Michael Chan: 'Cause you probably find yourself like adding a ton of props to those interfaces, right?
[00:16:26] Kent C. Dodds: Yes.
[00:16:27] Michael Chan: To make it, and then it's just kind of inside this big conditional mess of, well, if it's not a country selector, it's a whatever else selector.
[00:16:35] Kent C. Dodds: Yeah, so you may as well just make two separate components. Yeah, exactly. No, that's That's totally, totally it. And so, um, around the same time, I watched a talk at um the Phoenix.js meetup, or Phoenix React meetup that Ryan Florence gave, called Compound Components. Um, and I was just like really inspired by that that concept. It was the first time I'd heard of compound components. And uh so when I started building Downshift, I was like, okay, so we could have the Downshift And then we could have uh DownshiftInput, DownshiftMenu, DownshiftItem, uh DownshiftLabel for accessibility, um all these things. And so that's how I started. So if you watch the livestream, you'll see that's how I I built it initially. And then I got to this point where I was like, so I didn't understand this at the time, but compound components um are really good at um allowing you to to use components that share um implicit state. So they kind of hide the state behind the scenes. So like the isOpen state, the highlighted item state, all of that. And, uh, and so that's, that's nice because you don't have to worry yourself about that. You just use the components and they work together magically. Um, the, you, so many, like, you gotta watch this because the, the things that I did to make this work with, with context and I was like sharing the, um, component instance across these different components. It was just a nightmare, but it worked.
[00:17:58] Michael Chan: One of the, um, kind of challenges with this idea of inversion of control is state. And kind of state that comes from the developer who's developing it, or this, like you said, implicit internal state of the actual components. And I'm sure that it can feel at times like if you expose just a little bit too much of that, it feels like they're just reimplementing the whole thing from, from scratch anyway, and that maybe they're not gaining a lot of benefit from the components. Is that what you're talking about?
[00:18:28] Kent C. Dodds: Yeah, yeah, some people feel that way about Downshift as it currently is. Okay. And so, um, I, I got to a point with these compound components that I was like- I, in Downshift, there are 4 items of state, and it's always, it's always just been 4, which has always been surprising to me. But, um, there's the selected item, the input value, uh, highlighted item, and the isOpen state.
[00:18:47] Michael Chan: Okay.
[00:18:48] Kent C. Dodds: And, um, I found myself in building out this component and different ideas of how it could be used, I needed those items of state for one reason or another, whether it be styling the highlighted item differently or the selected item differently. I think that was mostly the use case. I was like, well, how do you do that? In addition to that, I didn't like how- like, let's say you want to have a styled input, like styled-components or Emotion, Um, and so now with my downshift input, it's rendering an input component or element. Sure. And you want to have it render your input component that you have styled and stuff. So now each one of these compound components takes a component prop and uh and you pass your own component. I hate the idea of a component prop. Really? Yeah, to me that communicates that um we are uh not giving you enough flexibility and control.
[00:19:45] Michael Chan: Okay, interesting.
[00:19:46] Kent C. Dodds: So I I didn't like that very much, but I like I couldn't think of any other way to do it, but I did need to get these, these 4, um, items of state somehow so I could like interact with them in some way. And so I thought, well, I have this component, maybe I pass them as props. Um, or like, I, I couldn't quite get it, but then I, I, I don't remember where I saw, uh, was reminded of the render props pattern. Mm-hmm. Um, but like Ryan and Michael Jackson have been talking about it a lot. And, um, I remember seeing it in React Spring. I think that's the first place it was really popular. Or not React Spring, but Motion. Yeah.
[00:20:21] Michael Chan: That was the first time I saw it at React Europe. I was like, what is this voodoo? Like, I don't even understand what this code does. This is magic.
[00:20:28] Kent C. Dodds: Yeah, yeah, most people had that reaction, I think. Um, yeah, and uh, I remember Merrick Christensen also was pretty into this. He called it function as child components. Uh, has a blog post about that a couple years ago. And uh, yeah, so I thought that was interesting. So I was like, okay, so I'll have another compound component called a DownshiftController. And that will use a render prop and I can get access. So anywhere I need it, I'll just get access. And as I was like working around with some of the examples, I slowly like, um just in the JSX, I'd have a Downshift controller here, one here, and I was like, why don't I just like do one bigger and it can encapsulate everything? Yeah. And I kept going bigger and bigger until it was like Downshift and then Downshift controller and the whole thing's a render prop. I was like, wait a second, maybe I should just make Downshift its itself a render prop.
[00:21:14] Michael Chan: Yeah.
[00:21:14] Kent C. Dodds: And when I made that switch, and I think I have that on the recording too, when I when I realized that and made that switch, then things started to really turn around. So at first there was like a performance issue that I thought I had, and I'm still not sure what that was, because Downshift's like crazy fast.
[00:21:29] Michael Chan: Yeah.
[00:21:30] Kent C. Dodds: Thanks to React, of course. And uh yeah, so I'm not sure what that was uh all about, but it's uh-
[00:21:37] Michael Chan: Was it about the certain the the build you were using?
[00:21:40] Kent C. Dodds: It could have been, yeah.
[00:21:42] Michael Chan: I remember seeing tweets about that. It was kind of never quite made clear what exactly it was.
[00:21:47] Kent C. Dodds: Yeah. What happened there? Yeah. And, and like, even in development build still, like I haven't been able to make it slow. Um, like the other day somebody said, hey, I've got 180,000 students I'm filtering on Downshift. And, um, and when you get that much, like you've gotta use windowing. I don't care what library you're doing. So, so we, he had uh windowing, but he was also using another library I made called Match Sorter that'll have like a, a human Um, like, or like a, uh, reason- human reasonable, I guess, um, filtering capabilities. And that was the, the thing that was slow. And so when I took that out, Downshift was like, yeah, having fun all day. Like, this is no problem. So yeah, Downshift is like crazy fast. And, and so anyway, anyway, um, I, I still wanna give credit to another person who really helped. And that is, um, I had a problem with, uh, I've got a bunch of props I need to apply to the input. And so I'm still using the compound components. Just downshift is now also a render prop, and then I have these compound components. So I wanted to get rid of that component prop and, um, um, but I still needed to somehow apply these props to the input. Um, like ARIA attributes for accessibility and things like that.
[00:22:59] Michael Chan: Because when you control the component, you can, you know, which props to accept, which ones you're going to get from your own render prop.
[00:23:06] Kent C. Dodds: Exactly.
[00:23:07] Michael Chan: But when you don't, if you want to invert that control and say like, you can use this with any input, like basic input elements or your own styled input elements, um, then you have to get a little bit creative.
[00:23:17] Kent C. Dodds: Exactly. Exactly. So I was like, well, shoot, I don't want to make it, uh, like- so the, the idea of inversion of control, which is what you're doing when you're implementing a render prop, is you, you give a lot more work to the end user, but in exchange they get a lot more flexibility. So it's kind of like Um, you know, it's in my mind, it's worth it. Uh, and especially with React's composability model, you can make your own implementation of a Downshift, and then you just use it like you would a normal thing. Um, but then you can dive deep if you need to get the flexibility. Um, but the problem is that now they have to start applying all the props that they need to. And um, and Jared Forsyth, I just randomly ran into in the San Jose airport around the same time. And um he said, I I showed it to, I was like, we were about to get on the plane and I wasn't sure I was gonna sit next to him or anything. So I was like, hey, listen, could we, um could I show you something really quick? I want your opinion. And uh he said, well, what if you had like this collection of props, like this object that you spread, you tell people to spread this on the input, like wherever they render it. I was like, oh, sweet. Yeah, that's a great idea. And so that's where the props collection um idea came came out of was, it's a just I I say, here's here's the props you should apply to your input, and now um all the you don't have to worry about it. So it's a little bit more work, but it's not so much that it's unreasonable. Sure. Um and um like the alternative was you have to render this Downshift input. Well, now you can render anything you want and just apply these props. So it's uh it's just as much work, it's just different work.
[00:24:49] Michael Chan: Um now are some of these props things um like accessibility related?
[00:24:53] Kent C. Dodds: Yeah, lots of accessibility and as as well as interaction. So as as you're typing, like an onChange, onkeyup, and things like that. Yep, exactly. Also, I I should mention Ryan Florence built uh React Autocomplete a long time ago. I think it was one of the first components he built. And I stole a lot of things from him. Like uh if you look at at React Autocomplete um and how it interacts with um event handlers on the input and then look at Downshift, it's like copy-paste in in some some areas there. So big thanks to to Ryan again. Um
[00:25:25] Michael Chan: that guy always seems to be ahead of the curve somehow.
[00:25:27] Kent C. Dodds: Oh, he is, yeah. He's great. And and now he's working on all this React Suspense stuff.
[00:25:33] Michael Chan: Yeah.
[00:25:33] Kent C. Dodds: Um, he's he's got like workshop material almost ready for it. It's not released yet.
[00:25:38] Michael Chan: Yeah.
[00:25:38] Kent C. Dodds: Yeah. He's um, he he has all the problems, uh, like that that require these solutions.
[00:25:46] Michael Chan: Yes.
[00:25:46] Kent C. Dodds: And so he, um, that's why he's ahead of the curve, um, is he recognizes, like lots of us, we just like, this is the world we live in. Yeah. For Ryan, he recognizes, no, this is a problem. It doesn't have to be this way. Yes. And and so he finds the solutions, um which is cool. And and the React team's doing that as well, of course.
[00:26:04] Michael Chan: Yeah.
[00:26:04] Kent C. Dodds: Um so anyway, one last thing on on building Downshift, or maybe a a couple more things. So um the prop collections is great, but um so I I'm applying an onChange, but what if you want to add your own onChange to the input? Now you're gonna override mine. And so that's when I change to prop getters, where it's a function that you call, and any props that you want to add to the input um you add those to the prop getter. So instead of input props and spread that across your input, it's getInputProps, that'll return an object that you spread across. And so then you call that with any other props you want applied, and then we'll compose that for you. So call yours and mine uh together to to make it work together. Uh so that's where prop collection or prop yeah collections went to prop getters. So that was cool.
[00:26:51] Michael Chan: So how has um how has that project continued to go? It's been about a year?
[00:26:56] Kent C. Dodds: Um, yeah, good question. I think, um, not quite a year, no. I think it's- I think I built it this year. I can't remember.
[00:27:03] Michael Chan: Okay, maybe it was around like the winter. I feel like it was cold.
[00:27:05] Kent C. Dodds: Yeah, yeah, it's cold and dark.
[00:27:09] Michael Chan: Um, Kenzie Dods emerged from the snow.
[00:27:12] Kent C. Dodds: Yeah, so I, I'm pretty sure I built Downshift a few months after Glamorous, like maybe 6 months after Glamorous. And Glamorous was April of last year. Okay. So yeah, I'm probably Um, around November or something.
[00:27:26] Michael Chan: Gotcha. And it's still um servicing the components at PayPal? Mm-hmm.
[00:27:31] Kent C. Dodds: Yeah. Yeah. Lots of uh components at PayPal are being— uh it's uh being used in there. Uh CodeSandbox is using it. They were the first-
[00:27:38] Michael Chan: Awesome.
[00:27:39] Kent C. Dodds: Uh Ivis was the first one to ship uh Downshift to production.
[00:27:43] Michael Chan: Wow.
[00:27:44] Kent C. Dodds: Uh yeah. So he beat me.
[00:27:45] Michael Chan: Another, another human that's in front of the curve. Yeah.
[00:27:49] Kent C. Dodds: Right. Like, yeah, that, that. That guy is just incredible. I, yeah, proud supporter of, of Evis for sure. He's great.
[00:27:56] Michael Chan: Yeah. I was, I was blown away at just the rapid trajectory of CodeSandbox in the React community. People just love it.
[00:28:05] Kent C. Dodds: It's, yeah, it's taken over. I'm, I'm featuring it in my talk, doing live coding in CodeSandbox, cuz it's just so great. I actually, I built Downshift in CodeSandbox, so the, the live, livestream. Um, I just couldn't beat the developer experience. No. Um, my editor wasn't good enough. So yeah. Yeah, that's great. And, and now I can use, uh, Sarah Drasner's Night Owl theme in CodeSandbox. Oh yeah. And I'm all set. Like I, I'm pretty happy there.
[00:28:32] Michael Chan: I love CodeSandbox, especially, um, do you use it for your trainings?
[00:28:36] Kent C. Dodds: Um, yeah. So like my advanced React patterns course and my beginner or intro to React, um, you can do the whole thing, including run the tests in CodeSandbox.
[00:28:46] Michael Chan: That's awesome.
[00:28:46] Kent C. Dodds: It's incredible.
[00:28:47] Michael Chan: Yeah, it's- he really, he really, um, came across something awesome there. And I particularly- for teaching, it is such an invaluable tool. And I had a friend who was just, um, who's learning coding for the very first time, like knew a little bit of HTML just because he had a, um, was it a Squarespace site? And so he had a couple things that he would like do in HTML or whatnot.
[00:29:14] Kent C. Dodds: I go to widgets. Yeah.
[00:29:15] Michael Chan: And, um, and so he was starting for the first time. And so I was like, okay, use- like, there are no other editors on the planet except for CodeSandbox. This is the only editor, right? And so he, he worked on it and you could tell, like, at some point he got a little bit of- a little bit like tired, just kind of like being in the sandbox. And I was like, I was like, dude, I'm about to blow your mind. Like, you just push the- like, you gotta create an account, but then just push this button and now it's like on the internet. And I was like, like, that is the feeling that I remember having when I started, where I was like, I could put an HTML file up on the internet and like, now anyone could see it.
[00:29:51] Kent C. Dodds: Yeah, you call your friend across the street and like, dude, go to this URL. It's like 30 characters long and it's got like 3 dots in it. Yes. Yeah.
[00:30:01] Michael Chan: Yeah, and I think that's one of the things that I, I love about that project is that he's, he's, he's found a way to kind of bring that that awesome experience of like, okay, I'm learning something and like, now it's on the internet. Like, this is awesome. I am amazing.
[00:30:18] Kent C. Dodds: Yeah. Yeah. Yeah. That's a, that's a wonderful feeling. And, um, I, I've built several applications that I'm using on a regular basis, 100% in CodeSandbox and deployed them. I never downloaded the code.
[00:30:30] Michael Chan: Yeah.
[00:30:30] Kent C. Dodds: It's, well, I mean, you download it in your browser, but sure. But yeah, never opened it in an IDE. Um. Locally, so it's amazing.
[00:30:38] Michael Chan: So what are some of the things that you find when you're teaching your classes on composition that people have the hardest time understanding? Um, even people who have been using React for a long time, like, what is the thing that kind of holds them back from these compositional patterns?
[00:30:56] Kent C. Dodds: Hmm. I think a lot of people assume that, um, these patterns are reserved for highly reusable and flexible components. Um, where that is true, it's not reserved, it's um, but they're very applicable to those kinds of components. Um, but they, these patterns are also really useful for uh separation of concerns. It's probably the biggest thing is, um, like with Downshift, it's separation of concerns. We're separating the logic for an autocomplete or a dropdown with the the way it looks. Yeah. Um, it's It's almost like classic uh Model-View-Controller. Uh the model and the controller live inside Downshift and the view is all yours. Um but it's implemented in within React's um uh composition model. And so it uh exposes a really nice and declarative and explicit um API. Um and so yeah, like it's perfectly fine to implement, and it's a great thing to implement these patterns for a one-time use component. Uh as a mechanism for separating concerns. Um, I think another thing that, that really trips people up is, um, uh, understanding that JSX and React is just JavaScript.
[00:32:10] Michael Chan: Yeah.
[00:32:11] Kent C. Dodds: And so like, um, when, when you and I saw the, the render prop pattern for the first time, we're like, what is this voodoo magic? Like, what is happening? But, um, if you like, a really valuable skill that everybody should learn, and, and maybe you can even practice this, look at some JSX. And transpile it, like code it yourself, React.createElement. Until you can do that and then do that in your head, um you you will be a little bit stuck. Um but if you can, once you are at that at that level, um and if we were at that level at the time, I at least I don't know about you, but at that time I was not at that level, so that's why I thought it was voodoo magic. But if I knew, then I could have just seen, oh, that's just passing a function as the argument to a to a function call.
[00:32:53] Michael Chan: That was when it clicked for me, is when I wrote it out as React.createElement and provided all the arguments. And I'm like, oh, I get it now. Instead of like doing a string or another element, I'm just giving it a function. That's when it all kind of clicked for me is when you take the JSX out of it. Cuz one of the hardest things about React is that JSX is awesome and I, I prefer it. I like writing in it, but there is back- there's a lot of baggage that I have from having written HTML for a long time.
[00:33:24] Kent C. Dodds: Yeah. Yeah.
[00:33:25] Michael Chan: And that kind of creeps up on me sometimes. I'm like, Oh yeah, I forgot that this is just a function and you know, doesn't have all of these characteristics of actual HTML.
[00:33:33] Kent C. Dodds: Yeah, exactly. And it's, it's not only that, but it also like, just because it appears in the children prop spot or it, it's called render or something like, just because, um, that's where it is doesn't mean that's how the component that you're passing it to is using it.
[00:33:49] Michael Chan: Yes.
[00:33:49] Kent C. Dodds: Um, and so like in, you look at any render prop component that's using children as the prop, then you're gonna see it's calling it's calling children, invoke that function.
[00:33:58] Michael Chan: Yeah.
[00:33:58] Kent C. Dodds: And so having a solid understanding of JSX is really just JavaScript kind of hidden behind a very nice, clean declarative abstraction. And then also JavaScript expressions really tie people up too. And so learning and understanding what you can put between those curly braces and what happens to the stuff in those curly braces in the transpilation process. Um, that, um, can really help too, cuz once you have that fundamental understanding, then a whole new world of, of possibilities opens up to you because you, um, you know that, oh, I'm actually just calling a function.
[00:34:38] Michael Chan: Yeah.
[00:34:38] Kent C. Dodds: It's, it's pretty simple.
[00:34:39] Michael Chan: Yeah. It's a, it, it really is amazing how that kind of becomes your hammer pretty quickly.
[00:34:45] Kent C. Dodds: Mm. Yeah, it does. Uh, it can be overused too. Yeah. Everything's a nail.
[00:34:51] Michael Chan: So your talk tomorrow, what's the big theme?
[00:34:54] Kent C. Dodds: So the big theme is, um, your components don't have to be complicated. So it's simply, simply React. So it also is kind of like, hey, let's take a step back. You don't have to have these big abstractions like state management libraries and things to accomplish great things in React. Um, and so like, you, all you need, you simply need React. Like it's simply React. Anyway, um, so the, the, uh, theme of the talk is we have an accordion. component. Most people can relate to an accordion or or can catch up pretty quick on on what it would be like to build one. Um and a lot of people can relate to this. So you build a component for a single use case, and then somebody sees that and says, that'd be great if I could use it over here. And you say, awesome. Um and then they add a like, oh, but I need it to behave differently, or I need it to look differently. Um and so you start adding props to this thing to support these use cases, which is fine. Um the whole the whole time you should be optimizing for deletability. And um and so like whether it's adding props or duplicating the code, it's it's probably fine. Like a single if statement isn't gonna kill anybody.
[00:36:00] Michael Chan: Right.
[00:36:00] Kent C. Dodds: Um the problem comes when more and more use cases keep going coming, and now your 30-line component is like uh 300 lines of conditional if statements in the in your click handlers and and set states and all this stuff. Uh and then somebody throws in Redux and and now nobody knows what the code is.
[00:36:19] Michael Chan: Well, and you have Like maybe 15, 20 lines of required props then too at that point.
[00:36:25] Kent C. Dodds: Yeah, yeah, exactly. Um, in my research for this, I found a date picker component that had 125 props.
[00:36:32] Michael Chan: Oh my goodness.
[00:36:33] Kent C. Dodds: Yeah, it's open source and quote, reusable. I'm sure it's reusable, you can use it for many use cases. Uh, but so there, uh, I I talk about that and most people can relate to that. Like you you've had a component that you start piling use cases on and it gets complicated. Uh, so that I call that the lifecycle of a component, not the component lifecycle, Lifecycle component. Uh, there are a couple problems with this. So your bundle size gets bigger for uh to support use cases that you don't really- for your app, it doesn't matter. You don't need them at all. Um, the- as a user of this, the API is really complex. So every single prop for every use case, you have to read like, do I need this prop? No, no, no. And like 30 props and like, oh, maybe I do. I don't know if I need that prop. And so, and then as a maintainer, you have to document all those and keep keep that documentation updated. And then implementing it is a a pain in the rear. And like anytime somebody wants to contribute, they have to learn this really big codebase. And so, yeah, you're always thinking about, am I breaking these use cases and things? So-
[00:37:37] Michael Chan: Well, and there's there's an additional cost of every time you use it, you kind of define that those props that are required for that. That space, but then becomes really difficult as maintaining the project to change those.
[00:37:50] Kent C. Dodds: Yeah, exactly.
[00:37:51] Michael Chan: Because now someone's gonna have- if they use your component in 50 places, they have- they, if they want to update, they have to change it in all of those 50 places.
[00:37:57] Kent C. Dodds: Yeah, exactly. That's where composition comes in. They should wrap it in their own, um, implementation or something. Then they only have to change it in the one. But still, like, it, it is, um, it is a maintenance and a user burden. Yeah. Um, as as a single component gets more and more flexible. Um, but it doesn't have to be this way, and I have this big reveal um in in my talk, um where you can you could implement a component that's that flexible, um just using a couple patterns that um invert control. That's that's the the biggest thing that I've discovered recently or or or learned recently is um the power of inversion of control.
[00:38:39] Michael Chan: Yeah.
[00:38:39] Kent C. Dodds: And so when when people keep asking you to add use cases, what they're really asking is, I need more control.
[00:38:45] Michael Chan: Yes.
[00:38:45] Kent C. Dodds: What they're saying is, I need more control. And so, by implementing certain patterns, you can give them that control and reduce the maintenance burden on yourself and increase the flexibility and simplicity for the consumers. And so, the the talk is mostly like, let's let's get on the same level here. We all know that this is awful. There's a better way to do this. Um, and then, I don't really explain how. I don't have time to get into the how you you implement these patterns. Um, but I do demo like, now that we have these things, um, when, when that person comes to you and says, I need it to look different, you literally just change this. And I'll, I'll, I have a little bit of, uh, live coding to, to show, like, so you just tell your coworker, copy these 25 lines, paste them, and move this. Yeah. And then, and that's all. Uh, and it's very straightforward. There's less, uh, less of API surface area. Yeah. Um, so like, uh, one of my favorite types of props is like render expand all button. Mm-hmm. Um, and you don't need something like that when you give people a render prop, because they literally- if I don't want to render the expand all button, I remove that code. Yes. And, and it's very clear. Nobody needs to learn an API or props for that. Mm-hmm. Um, so yeah, that's the, that's the idea of the talk. And, and my hope is that people will, um, be inspired by that to at least learn the patterns and, and find places to apply them, um, appropriately. Uh, and then also, uh, go and discover new patterns as well. The cool thing about software is that we're we're not learning or not discovering anything new most of the time. It's like, you know, 20 years ago in computer science they figured this thing out. Now how does that apply in React? Um, and so yeah, looking for uh different ways that we can um increase the uh flexibility of our APIs and the simplicity at the same time. Yeah, that's what I'm excited about.
[00:40:34] Michael Chan: Nice. Well, I really like this. I'm I'm excited to hear you talk and Thinking about what you're saying and kind of how that applies to libraries like Downshift, um, it feels, it feels more akin to this idea of a library, right? Where I am giving you a library of components that you can use to compose a dropdown, right? I'm not giving you just a dropdown. I'm giving you the toolset to create one. And with that is the power to say, you know what, this one part of this whole equation- like, I love 99% of it, but like, I really wish that it did this one thing. We can just pop the dropdown version out, write your own, and still keep the 99% benefit of using that library, as opposed to having to throw the whole thing out because there's one module that doesn't work quite like, like you want.
[00:41:22] Kent C. Dodds: Yeah, exactly. And, and in that scenario, you're like, okay, I guess I'll file an issue. And then the maintainer's like, oh no, another issue.
[00:41:30] Michael Chan: There's so much complexity. I don't know how we can support this one last
[00:41:35] Kent C. Dodds: Yeah, exactly. And then burnout.
[00:41:36] Michael Chan: Burnout, yeah. Done. Somebody else take it.
[00:41:39] Kent C. Dodds: Yeah. Yeah. These patterns are really cool and exciting, but I I in my talk, I also give a caution about like, hey, listen, like we're shipping products, we're not shipping code.
[00:41:49] Michael Chan: Yeah.
[00:41:49] Kent C. Dodds: Um, and so it it's just just remember that as exciting and fun as these patterns are, um there is opportunity for overuse and premature abstraction. So if you're gonna toss uh like That I think one of the most important things that we should be optimizing for when building software is deletability. Because there's nothing more consistent in our industry than change. And the design will change, the um the business requirements will change, everything, like it's constantly changing. So you need to be able to be flexible enough to change.
[00:42:22] Michael Chan: Yeah.
[00:42:22] Kent C. Dodds: Um and so some of these patterns are are really good at that, like um a render prop versus When when I have control over rendering, um then I like I I'm not as flexible for you. Um but if you have control over rendering, then you are plenty flexible and and you can make those changes. So that that does kind of help optimize for change. Uh sometimes that can be a premature abstraction where it can make it harder for you to to make changes as um requirements come along, because uh you're trying to solve for the world and you only have one use case.
[00:42:54] Michael Chan: Yeah.
[00:42:55] Kent C. Dodds: So it's important to to keep that in mind as well. There's nothing wrong with an if statement. There's nothing wrong with a ternary. I prefer ternaries, but there's nothing wrong with these things with conditional logic. Like at some point you gotta ship something. Um so I I would generally recommend, like until you have uh 3 relatively distinct use cases, um don't abstract uh too early. I I would rather duplicate the code than um have a a bad abstraction.
[00:43:23] Michael Chan: Yeah, one of my favorite Ruby developers, Sandi Metz, always kind of talks about this idea of that design, when applied correctly, is allowing you to defer design. You're you're optimizing for change, knowing that like another another requirement's gonna come down the pipe, and you know, like the customer's not gonna like this thing. And if you spend too much time trying to like make this thing perfect, something's inevitably gonna break it. You you said like the only constant in our job is change. And every time kind of coming back to, do we have to solve this problem now? Or can we like, kind of like kick it along until we have a little bit more information? Um, I feel like that's, that's a really strong skill to have as a developer.
[00:44:05] Kent C. Dodds: Yeah. Yeah. Well, one that I'm, I'm definitely still working on. I get really excited by these patterns. I'm like, sweet. Just like throw that in there. Put a render prop on that thing. Like, you know, whatever. Um, but, uh, yeah, it, it adds complexity for sure. It does. Um, and so, yeah, a function adds complexity, like you You could you could take a 5-line function and make 5 functions out of it.
[00:44:25] Michael Chan: Yes.
[00:44:26] Kent C. Dodds: Um, and for what? Um, so like when when people make a bunch of components out of a a single, like you got a single component with, um, I don't know, like 50 lines of JSX and you're like, oh snap, we gotta make like 7 components out of this thing. Like, okay, let me, first of all, that all that JSX, it's just a giant expression. So there's not too much going on in there. Like it it. It's unlikely to break. Um, so what are you really getting out of this abstraction? Um,
[00:44:57] Michael Chan: yeah, I like to stay in one file for as long as I possibly can.
[00:45:00] Kent C. Dodds: There's, and there's nothing wrong with that. React is capable of you building the entire application as a single component.
[00:45:06] Michael Chan: Cool. Well, um, we've been recording for almost 50 minutes now, so-
[00:45:10] Kent C. Dodds: We had a good time.
[00:45:11] Michael Chan: We did have a great time. So in closing, uh, I just wanted to ask what What projects and people are you super excited about in kind of React and JavaScript right now?
[00:45:22] Kent C. Dodds: Yeah, so uh Brent Jackson comes to mind because my slides are using his MDX deck.
[00:45:29] Michael Chan: Yeah.
[00:45:29] Kent C. Dodds: Um, he is- we were talking earlier, he's prolific, just so much stuff.
[00:45:34] Michael Chan: So amazing.
[00:45:35] Kent C. Dodds: And, and yeah, just like, yeah, I'm just playing around with this amazing awesome thing that I'm just throwing out there. Yeah, so
[00:45:41] Michael Chan: that library in particular Like he announced it and I was like, oh cool, like it, you write a Markdown file and it shows your slides. And then you opened up just now and there's like a full presenter mode. It shows you like the next slide that's coming up.
[00:45:53] Kent C. Dodds: And this is like 2 weeks of work for him. And I'm like, what? And and it synchronizes multiple windows. Uh yeah, it's just, it's, it's amazing. Really cool stuff. So yeah.
[00:46:04] Michael Chan: So I co-sign on Brent Jackson.
[00:46:07] Kent C. Dodds: Yeah. Yeah. Great. He's, he's just fantastic. Um. And uh he works with um that Murmurs or- Yeah. The cat um avatar. Yeah. Um that individual is also uh just impressive, impressive person. Sunil Pai is my um unsecret lover. We he's just the greatest. Um I yeah, he's just an awesome, awesome person um who inspires a lot of really good ideas. MDX was inspired by his idea. I built Babel plugin Makros that's taking off, that was inspired by him.
[00:46:42] Michael Chan: CSS-in-JS, he had a lot of hand in that early development.
[00:46:47] Kent C. Dodds: Yeah, he he did has made a really big impact. Now he's doing React VR stuff, just like genius and a half. And so I really admire his stuff. Sarah Drasner, I'll never be over her. Just she's she's an incredible developer. Marcy Sutton is always doing great stuff for the accessibility community, so I'm always She actually- I'm glad I remembered to think of her because she helped a lot in the accessibility of Downshift.
[00:47:15] Michael Chan: Awesome.
[00:47:16] Kent C. Dodds: And so Downshift, as far as I know, in my testing, Downshift is the most accessible component of its kind, and it's in large thanks to Marcy for the help that she she put in there. And yeah, Nitin Tulswani, he's an India. I've never met him. I'd love to meet him sometime, but he just builds the craziest stuff.
[00:47:39] Michael Chan: Yes.
[00:47:39] Kent C. Dodds: Like, um, it was Redox, Redox. Yeah. So, uh, React renderer for Word documents. Like, what? I think he did it for fun, but like, he was, he was very involved in, in Glamorous, like, on the kind of on the outskirts. So he built Glamorous Primitives, uh, he made, uh, like, uh, Glamorous, uh, he rendered Glamorous to Sketch, he rendered, rendered Glamorous to Word. Uh, just like did all this amazing, really cool stuff. Now, uh, since I deprecated Glamorous, um, he made Emotion Primitives. Oh, nice. Yeah, so he's he's just jumping all over, really awesome, impressive stuff. So I'm I'm huge fan of him. Also Sean, I don't know his last name, but he spoke here at React Rally. Um, he's just been really inspirational for a lot of people, I think, and I really appreciate him.
[00:48:28] Michael Chan: Yeah.
[00:48:28] Kent C. Dodds: Um. There's a lot of people I could keep going. Um, Ryan Florence has been a really big inspiration for me too, so I'm happy to know him. I call him my friend, and uh just, he's a great person. Uh, like, more than just a developer, he's a good, really good person.
[00:48:44] Michael Chan: Really human.
[00:48:44] Kent C. Dodds: Yeah, so I'm glad to know him.
[00:48:48] Michael Chan: Yeah, well, we'll link all of these people so that- In the podcast, you can find them.
[00:48:52] Kent C. Dodds: Go follow them on Twitter. Yeah, they're great.
[00:48:53] Michael Chan: Awesome. Well, thank you so much for being on the show. Um, I know that what you have to say is gonna help a lot of people, so I appreciate your time. Uh, appreciate the fact that you're putting all of these great things into the world and helping people get better every day.
[00:49:08] Kent C. Dodds: Thank you. Thank you. Can I say one more shout out? Yeah, of course. Okay.
[00:49:12] Michael Chan: Always.
[00:49:12] Kent C. Dodds: Uh, if you, if you care about testing in React, React Testing Library is great. Give that a look.
[00:49:23] Michael Chan: Links and show notes for this episode can be found at reactpodcast.com/21. You can now support the show on Patreon by visiting reactpodcast.com/partner. Your partnership goes a long way to support the ongoing production of this weekly show. Thanks for listening. We'll see you next week with a great conversation with Ryan Florence about Reach. UI.
chantastic.fm