107: Sara Vieira on The Opinionated Guide to React
I'm sorry for the sparse notes this week.
Truth is I got admitted to the hospital with my daughter this weekend and have not had a chance to collect them.
I'll post them when I return.
But, let's be honest, the book link is what matters most :)
Featuring
Sponsors
Infinite Red
In over your head with a React or React Native app? Infinite Red can help. They're React Native core contributors who've been designing, building and shipping apps for over 10 years. reactpodcast.infinite.red
Transcript
[00:00:00] Michael Chan: This is React Podcast. I'm Chantastic. Today on React Podcast, Sara Vieira tells us about her new book, "The Opinionated Guide to React." She breaks down her experience building large-scale React applications into 11 chapters of easy-to-digest gold for React noobs and seasoned pros alike. At the end of this chat, she blows my mind with both her unique approach to building her book and how she's building purchase parity power into every copy sold. Don't know what that is? I didn't either until the end of this episode. So you are in for a treat. Before we dive in, thanks to Infinite Red for supporting this episode. Having access to developers that know the direction React and React Native are headed can be a huge advantage to your development team, giving you more time spent satisfying customers and less time spent migrating from one state management solution to another. If you don't have developers who know React and React Native like the back of their hand, hire Infinite Red. Infinite Red has been designing, building, and shipping apps for 10 years, and they want to bring that expertise and industry connection to your apps. Infinite Red has a sweet deal right now where you get $750 for referring a new project. Get expert help from Infinite Red by visiting reactpodcast.infinite.red. Sarah Welcome back to React Podcast.
[00:01:37] Sara Vieira: Thank you. It is my third time. It's not like I've been counting.
[00:01:41] Michael Chan: I know. Well, okay, so I was doing some- doing a little bit of math, and I think like if you exclude Michael Jackson, who was like, you know, hosted the show, um, you're- you'll be the most.
[00:01:52] Sara Vieira: Still a lot of things- a lot of interesting things happen in my life, you know, like a lot of interesting shit.
[00:01:59] Michael Chan: I like- I wish that that was a redeemable achievement somewhere like that, you know, being on the show 3 times got you anything. I'm sorry that, that it doesn't, but-
[00:02:12] Sara Vieira: Do you have t-shirts? Like, I'm a developer, I would sell my soul for swag.
[00:02:17] Michael Chan: You know what, I don't. I should make a t-shirt for you though. I feel like, I feel like if anyone deserves it, it's, it's you.
[00:02:23] Sara Vieira: Put it on Redbubble so I have to buy it. That is a true move.
[00:02:34] Michael Chan: Oh, okay, okay, we're gonna have to- we're gonna have to make a- make a t-shirt just- just for you. Just for you. What do you want on it?
[00:02:41] Sara Vieira: I mean, honestly, just the logo would be fine, and like 3 times or something like that.
[00:02:46] Michael Chan: Okay.
[00:02:46] Sara Vieira: I don't know.
[00:02:47] Michael Chan: All right, all right.
[00:02:48] Sara Vieira: I'll think about it and I'll get back to you. I don't know, you just got me on the spot right now. I'll use the fact that it's 11 PM, even though I go to sleep at 3 AM, but I'll use that. It's like, it's 11 PM, Michael, you can't just put me on the spot like that.
[00:03:01] Michael Chan: I'll have to get some, maybe, uh, you know, if you're listening to this episode, shout out, tell us, uh, tell us what kind of design would be cool. We're gonna make, uh, Sarah a a a T-shirt for being the the most guested person on React Podcast, just 'cause I like talking with you so much.
[00:03:16] Sara Vieira: Oh, thank you so much.
[00:03:18] Michael Chan: So you have, you just launched a book and I am super excited about it. Um, I haven't bought a copy yet. I'm gonna buy it right after this, right after this conversation. Tell me tell me a little bit about it. It's called Opinionated React, which I'm super jealous of that domain, by the way. Um, and tell me tell me tell me about it.
[00:03:37] Sara Vieira: If it makes you feel better, I bought the domain and I misspelled it, so now I have two. So do you want the misspelled one?
[00:03:43] Michael Chan: I'm good, I'm good. I'll leave I'll leave the whole space to you. I like the-
[00:03:48] Sara Vieira: It's called Opinionated React. It's missing an N. If you want that, just hit me up. I got you, fam. I got you.
[00:03:55] Michael Chan: Isn't isn't that the worst feeling? Like you go to, you rush to go get a domain real quick and then like you it wrong. You're like, man.
[00:04:03] Sara Vieira: You should know that I don't know how to spell opinionated properly. So like every time people are like, send me something and I was like, can you email me at Sarah at, and then I go on like the pasty app that I have to go through all my things that I copied and pasted and just go to like opinionatedreact.com and paste it. Because every time I try to write it, I can't. Like, you should know that, like, okay, to anyone who doesn't know, like, I'm not a native English speaker and I've learned through talking. So like, I sometimes I just don't know how to write words and I'm like, but I should know because it's my domain.
[00:04:36] Michael Chan: I love it. It didn't it didn't it didn't stop you from like buying it though, which I love 'cause I've made that same that same uh mistake of eagerness. Well, you know, okay, before we dive into what the book's about, I just like bless you and your family for like not calling this like React best practices. Can we can we start from there? 'Cause like that shit drives me-
[00:04:57] Sara Vieira: There are best practices. That would kill everything I know about myself. My wife would divorce me and my mom would disown me if I called something best practices. I don't think there's such a thing as best practices. I think it's like whatever works for you works for you, man.
[00:05:12] Michael Chan: Yeah, I feel like it's just SEO bullshit, right? Like for some reason it's like that, like people are searching for that stuff to like get, get, I don't know, maybe like a, like fast track things that they don't know about. But man, Like, so many of the best practices that I see out there are just total horseshit.
[00:05:28] Sara Vieira: And even if they're not, I feel like you have to have some- like, there's gotta be something in you that actually writes. And imagine, assuming you didn't write the library, because if you did, I get it. But like, you didn't write the library, right? Let's assume like you just use it and you're like, I know the best practices of this library that I didn't write.
[00:05:46] Michael Chan: Right. Like, like, it's all right if Sebastian and like the React crew like have, have strong opinions about like what is a better or worse practice. Like in React, right? But like-
[00:05:56] Sara Vieira: Yeah, they made it. That's valid.
[00:05:58] Michael Chan: Yeah, yeah, yeah. But like, if you're, if you're like, like a consulting React developer, like, you don't know.
[00:06:05] Sara Vieira: You can say like, these are the things that worked for me.
[00:06:07] Michael Chan: Yeah.
[00:06:08] Sara Vieira: Yeah, no, I didn't know. No, I did not call it the React best practices. So it sounds like opinionated- I would get, like, I'm a woman in tech, like I would get so much shit.
[00:06:19] Michael Chan: Oh yeah, you would just get massacred.
[00:06:21] Sara Vieira: Oh my God, I would get killed on the internet.
[00:06:25] Michael Chan: I would, I would, I would like- yeah, if you- if we were talking about your book right now and it was React Best Practices, I would, I would, I would worry for your life. We'd have to, we'd have to squash that episode.
[00:06:34] Sara Vieira: Okay, carry on. Yes, yes, no, I would not call it React Best Practices. Okay, cool.
[00:06:42] Michael Chan: So you called it Opinionated React, which I, which I freaking love. I think it's, I think it's great. Um, kind of tell me about the perspective that you, you have writing this book And like where the opinions come from.
[00:06:53] Sara Vieira: So like I've been using React for a while and I've been using React in a gigantic application called Sandbox for about a year. And before that I've used it in small projects and I've used it in medium projects and blah, blah, blah, blah, blah. And I've used it to put into an Angular 1 app. That was terrible. Continue. It was like, it was glued together with Polymer. I don't, I don't know how-
[00:07:16] Michael Chan: Oh my word.
[00:07:17] Sara Vieira: I know. So like, you had- okay, not the point. Um, the point, I still dream about it, it was like 4 years ago. Um, the point is, uh, like, I've used a lot of things with React. Like, I don't know what the best practices are. Like, I know some things, like, but like everyone knows those kinds of things. Like, I'm not thinking- I'm not remembering anyone, but like some, I don't know, like test your code and like stuff like that, you know. People are like, 10 best practices, and they're like, test your code, name your components. And I'm like, thanks, mate.
[00:07:48] Michael Chan: Great, thank you.
[00:07:51] Sara Vieira: Thank you, so helpful. Um, point is, uh, like, I think there's a lot of like- so I think there's 2 types of applications and then 2 types of frameworks, and then there's Vue. So like, you have Angular in which- or Ember, for example- in which everything is opinionated by default, kind of like Rails. So it's kind of like you're writing JavaScript, but with WordPress on top of it. I don't know. I've never used Rails. So it's like, it's like, like WordPress, you know, but for- I don't know.
[00:08:20] Michael Chan: Yeah. It's, it's very like heavily structured, right? Like
[00:08:24] Sara Vieira: they have all the opinions there and already all the packages come with it. So you don't really have to think about like, what am I gonna do for this? It's all there. It's fine. And then you have React, which has Nothing.
[00:08:37] Michael Chan: Yeah. It's like kind of like a, a blessing and a curse, right? Yeah. Yeah. Like on one side, like we got into it because like React is so unopinionated that we were able to, to do all of the things that we couldn't with these like heavily like guarded frameworks. Yeah. Um, but then on the converse of that, it's kind of like, well, now we have this whole community that does everything in like, you know, 7 ways to Sunday. Like what's good, right?
[00:09:03] Sara Vieira: Yeah. And I also like think like that's actually one of the things that I mentioned in the book is like the problem with React is that there are too many packages, but how can that be a bad thing? That doesn't sound like a bad thing. That sounds like a great thing. You know, like, yeah, well, it's kind of daunting. You don't know what the fuck's happening. So like,
[00:09:21] Michael Chan: yeah,
[00:09:22] Sara Vieira: that was one of the things. Also another one of the things is like, so you have like useState, right? Okay. Yeah. The middle one is Vue. What I want to talk about Vue. Is that Vue has- is not super opinionated. Like it's still just a view layer, but it does, it does pick their quote unquote sides. Like if you go to the Vue website, you know that you like, you can use React Router and it- sorry, Vue Router, and it's maintained and kept up to date with Vue. Like you can use whatever you want, but this is what they like tell you. Like, we know this is a thumbs up and Vuex is the same thing, which is kind of like a state the state, the de facto almost state management for Vue. So it's like you have kind of the best of both worlds.
[00:10:04] Michael Chan: Yeah.
[00:10:04] Sara Vieira: In which you have all the flexibility you want, but you also have a core team being like, maybe this is good. You may not like it, and if you don't like it, there's other options and you're not blocked by it. But maybe you'll like it and then we can be friends. So, and I think my idea was a bit like trying to at least put my opinion, even if the things that I choose are not the best ones, they're at least one that you can look at and see. And also, I, uh, my thing is that I think hooks are kind of hard. Like, not useState, but useEffect is very confusing.
[00:10:41] Michael Chan: It is. There's a lot to know.
[00:10:43] Sara Vieira: Yeah, exactly. So I wanted to also go like deep dive on hooks in general because I think that's actually quite confusing. Like there's a lot of hooks that are quite confusing, to be honest. And I wanted to go like deep down on some of them. And I learned a lot about useEffect, to be honest. I did an entire talk about useEffect.
[00:11:03] Michael Chan: Yeah. Well, it's really, it's really interesting, right? Because like, you know, useEffect replaces so many of the component life cycles and it does so in an extremely nuanced way where it's like, you have this one API and you're like, oh, sweet. Like this replaces so much stuff. And it's like, You have to know so much about the ins and outs of like how and when and like what things to pass into it and why.
[00:11:24] Sara Vieira: Did you ever return null from a useEffect? I think that was the funniest shit that ever happened to me. No, what happened? It says destroy is not a function.
[00:11:33] Michael Chan: Whoa.
[00:11:35] Sara Vieira: It's like, what? Or your return function returns null. Something like you have to return null in a specific way. Okay. Sometimes you're like, you're in a function and you just return null. Like that's what you're used to do, kind of. So you're like, return null, destroy is not a function. I'm like, what the fuck? I'm sorry.
[00:11:54] Michael Chan: All your base are belong to us.
[00:11:57] Sara Vieira: Yeah, and it's just like there's a bunch of like small nuances about stuff like that that I wanted to get into, also like for my own learning a bit.
[00:12:06] Michael Chan: Yeah.
[00:12:06] Sara Vieira: And to see if I could understand it and if I could explain it. So I think that's the only way you can truly understand it. That's why I even did the useEffect talk before I released a book to see if what I was saying actually made sense.
[00:12:20] Michael Chan: Yeah. I haven't seen this talk. So what's the high level of the uh the useEffect talk?
[00:12:24] Sara Vieira: Uh it's basically me fucking over with useEffect for 45 minutes and being like, does this make sense? No. Let me explain why it actually makes sense.
[00:12:33] Michael Chan: Yeah.
[00:12:34] Sara Vieira: Why does this say destroy is not a function? Because you cannot return null from an effect. Like, it's basically a lot of stuff like that. And like also going through like how you can use useRef to like only run an effect after a component changes.
[00:12:50] Michael Chan: Right.
[00:12:51] Sara Vieira: Because I think that's also very confusing in which you're like, okay, this is gonna run when it changes and then it runs on start and you're like, wait, what? Wait, what? And then it makes sense. I think my main discovery in the beginning when useEffect came out was that I was like, oh my God, I don't have to put an empty array, I can put anything.
[00:13:09] Michael Chan: Yes.
[00:13:10] Sara Vieira: Yeah, you can put- you can put lol in it, and because it doesn't change, it doesn't matter.
[00:13:17] Michael Chan: Yeah, anything that doesn't change, right?
[00:13:19] Sara Vieira: And I think that honestly, right in the beginning- I don't think it was right in the beginning, I think I'm exaggerating, it's probably like a month afterwards or something like that, like easy. Um, like when I realized that, it just opened up a new world that like a lot of the dependency things started making sense.
[00:13:35] Michael Chan: Yeah.
[00:13:35] Sara Vieira: Because like it was just mentioned as like, here's an empty array, use that. And I'm like, okay.
[00:13:41] Michael Chan: So what do you use? Do you use like LOL or WAT or, you know, you change it up every time?
[00:13:47] Sara Vieira: I work in a professional company, Michael. I use ESLint disable exhaustive hooks.
[00:13:54] Michael Chan: I know I have that like bound to like a- I have certain like disable ESLint rules, like just bound to keyboard shortcuts. Cause I'm like-
[00:14:04] Sara Vieira: I think that's also a thing. The more you understand about useEffect, the more you actually use that rule.
[00:14:09] Michael Chan: Yeah. Yeah. Yeah.
[00:14:10] Sara Vieira: Which is really weird. Oh my God. We had this version, really old version of the CS Lint plugin that still did auto-fixing and it broke prod and I almost cried.
[00:14:20] Michael Chan: Oh, really?
[00:14:21] Sara Vieira: Because we set a dependency to like, like object.value basically, but object was null. And it turns out that we had a really old version. It doesn't do that anymore, probably because of problems like this.
[00:14:32] Michael Chan: Sure, sure, sure.
[00:14:33] Sara Vieira: I hate my life.
[00:14:34] Michael Chan: So you've been at CodeSandbox for like a a year now?
[00:14:38] Sara Vieira: Yeah, I joined last March, I think.
[00:14:41] Michael Chan: Oh, wild. So it's like a year and a half.
[00:14:44] Sara Vieira: Holy shit, yeah.
[00:14:45] Michael Chan: Or I guess it's still March, right? The coronavirus started in-
[00:14:48] Sara Vieira: It's still March, yeah.
[00:14:49] Michael Chan: It's still March.
[00:14:50] Sara Vieira: March 135.
[00:14:52] Michael Chan: So you've been there for a year plus, you know, 150 days.
[00:14:57] Sara Vieira: It may be my longest job. No, I'm kidding.
[00:15:00] Michael Chan: Really?
[00:15:00] Sara Vieira: Actually, maybe. No, I was more at another company. I was more time at another company. At my old company, I was longer. I was 2 years. Yeah.
[00:15:09] Michael Chan: Okay. How how much has your work there- I mean, you've been doing React for a really long time, but how much has your of your work at CodeSandbox, which is, you know, an incredible undertaking, um, how much has that informed the the kind of like chapters and structures and ideas in the book?
[00:15:28] Sara Vieira: I mean, it helped a lot. So like before I joined CodeSandbox, I was a developer advocate, like which means that I coded small things. So like I didn't quite understand the complexities of like- I did kind of, and not really in React, of making like really huge apps.
[00:15:43] Michael Chan: Okay.
[00:15:43] Sara Vieira: And so like I do think that CodeSandbox really, really helped in me understanding what are the complexities of building huge apps, of like things that sound like a good idea but then no. So like one example, fetching things using useQuery, right? Or mutating things using useMutation.
[00:16:02] Michael Chan: Okay.
[00:16:03] Sara Vieira: Like I I talk about that because I think it's a nice thing, but like, can you imagine all of our views filled with that when you have to make optimistic updates?
[00:16:12] Michael Chan: Right.
[00:16:12] Sara Vieira: It's exactly that kind of thing that I think I learned a lot, which is like sometimes the like the easiest way, the way that you're like, just to just to do that, that's easy. Um. You're gonna cry after a while.
[00:16:26] Michael Chan: Yeah. Yeah. Yeah. No, it's really fascinating, right? Because there's, there's almost like two sets of advice for like any type of programmer, right? 'Cause you have that kind of like, hey, just be free. Like, you know, while you're, while you're young in this thing, like just do whatever you want. Do, do it. Yeah. Just have fun. But then there is that shift where now you're working on this project and like everything just feels like super critical and like these, you know, a minor change can really mess something up in a really big way. Like, do you find that- I mean, we, we kind of jab at ESLint and all that kind of stuff, but do you, do you find that that kind of stuff becomes more critical in an application that is large and has like really heavy constraints around its like performance?
[00:17:10] Sara Vieira: I find that the thing that actually becomes more critical is CI.
[00:17:14] Michael Chan: Gotcha.
[00:17:14] Sara Vieira: Because you don't run lint or TypeScript or whatever every time you save, but you run CI.
[00:17:20] Michael Chan: Yeah.
[00:17:21] Sara Vieira: So like, I think the thing that you kind of ignore in the beginning when you're making something is CI. Like, you don't really set it up. You're like, it's fine. I can tell when my site's broken.
[00:17:30] Michael Chan: Yeah, I'm good. I'll click around. I know when it's fast.
[00:17:33] Sara Vieira: Yeah. If I if I get an error notification, it's fine. Uh, then I'll look at my Netlify builds and it hasn't deployed to production in 3 days and I'm like, oh my God, what happened? Um, has this happened with the Queer.js website? Maybe. Uh, point is. Like, I think the bigger you get, the more there is a need to like, um, stream the the changes in PRs and actually find a way to get PR builds and find a way to get like good CI that runs lint and runs all of these things.
[00:18:03] Michael Chan: Yeah.
[00:18:04] Sara Vieira: So that you can be sure that when you merge in, I mean, you were never sure, but you can be kind of sure that when you merge it, it's not gonna break everything. So I do think like the most value that I've seen honestly is CI.
[00:18:17] Michael Chan: Interesting.
[00:18:18] Sara Vieira: CI saves my- saves lives, man.
[00:18:20] Michael Chan: Oh yeah, absolutely. Like there's nothing more like reassuring than like having, having that set up properly and then getting the okay from CI. Cause you're like, okay, well this is-
[00:18:31] Sara Vieira: You know, it's really sad. Our, our CI also deploys to, um, so if you have a PR, you can, and if you're like a part of the CodeSandbox repo, obviously not everyone, that would be fucking weird. You can also deploy any PR to Stream.
[00:18:43] Michael Chan: Oh.
[00:18:44] Sara Vieira: Which is our, uh, yeah, which is a staging environment.
[00:18:47] Michael Chan: Okay.
[00:18:47] Sara Vieira: Uh, but the problem is, it's just like, it never goes green unless you deploy it to Stream. So it's like, sometimes I'm just like, oh, it's still running. It's been done for like 20 minutes, but I'm like, I never get the green. It's so sad.
[00:18:59] Michael Chan: All I want is more green.
[00:19:02] Sara Vieira: Exactly. Always yellow, never green.
[00:19:04] Michael Chan: Now, do you have um checks in CI for certain performance metrics? Um, 'cause those are, those are really things that you can't necessarily know when you're like in in development, right? Or like when you have like a runaway useEffect on accident or or whatnot. Um, how do you check for those kind of things?
[00:19:25] Sara Vieira: Honestly, uh, we don't have a lot of- we have integration tests, which will time out, for example. We don't have a really high timeout, but we don't really have a lot of performance tests, which is something that we're trying to get better at.
[00:19:39] Michael Chan: Sure.
[00:19:39] Sara Vieira: Because it's such a huge application that the thing is about the performance of CodeSandbox is that it also depends on what you're opening.
[00:19:46] Michael Chan: Okay.
[00:19:47] Sara Vieira: So like if you open the React new sandbox, it's gonna be like 100 times faster than if you opened the entire code sandbox repo.
[00:19:57] Michael Chan: Sure.
[00:19:57] Sara Vieira: So like it also depends a lot. And for example, the dashboard doesn't- so for example, the editor is only loaded in the editor. We don't load VS Code anywhere else. So like if you go to any other page, you're like, wow, this is so fast. Page splitting. Um, route splitting, page splitting.
[00:20:15] Michael Chan: Code splitting?
[00:20:17] Sara Vieira: Code splitting. Code splitting. Per page. Yeah. Um, so yeah, we have some issues of trying to figure out like, are these things like, are um, are the sandboxes fast enough? 'Cause it's a lot of the times it's not even like the change of code that's fine. The issue is that like VS Code is like 3 megabytes or something. I don't know.
[00:20:39] Michael Chan: Yeah.
[00:20:40] Sara Vieira: Vse told me. So like there's not a lot that we can do To like fix it. It's really not in our like hands to fix it. Cause it's like 3 megabytes. Like we can make everything else super fast. And like our dashboard is super fast. We just redid the dashboard and we're also redoing the profile and stuff like that. And most of it is super fast. Our homepage is also super fast, but like it's 3 megabytes, Michael.
[00:21:06] Michael Chan: Yeah, that's, it's a lot. Um, so like once it's, once it's loaded though. Your like kind of actual coding experience kind of carries on pretty quickly after that though, or at least that's been my experience.
[00:21:18] Sara Vieira: Yeah, in general, yeah. Unless you run into some like weird issues with internet or something, it usually is pretty fine, but it takes a while to load.
[00:21:26] Michael Chan: Yeah, yeah.
[00:21:27] Sara Vieira: That's why we even put on the skeleton, because people are like, is like, is this, um- yeah, so now we have skeletons everywhere. We did kind of fix it from the perspective of uh if you open /s to create a new sandbox, we actually load you a lot of the editor in the background so that when you click a sandbox, it's way faster to actually open it.
[00:21:47] Michael Chan: Oh, nice. That's awesome.
[00:21:48] Sara Vieira: It's pretty cool.
[00:21:49] Michael Chan: Interesting. Interesting. Well, I want to get away from CodeSandbox for a minute. I want to come back to your book because I want everyone to buy your book and have a really good time.
[00:21:57] Sara Vieira: I get paid by commission. No, I'm kidding. I can only eat if I talk about CodeSandbox.
[00:22:04] Michael Chan: Okay. So, let's talk about- let's talk about Code Sand- not Code Sandbox. Thank
[00:22:08] Sara Vieira: you for wanting food on my table, Michael.
[00:22:11] Michael Chan: Code Sandbox, Code Sandbox, Code Sandbox. Okay. Did we get it in enough? Yes.
[00:22:15] Sara Vieira: Okay. I have 3 burps for the rest of the week. I'm good. Carry on.
[00:22:18] Michael Chan: Okay. So, you have this- you have this book, Opinionated React. You just- you just launched it. It looks-
[00:22:25] Sara Vieira: I want you to know that it's called Opinionated Guide to React, but I thought the domain was too big.
[00:22:29] Michael Chan: Oh, okay. Thank you. Thank you. Yeah, the Opinionated Guide to React at opinionatedreact.com. And you talk about like all these really great, um, I just want to make sure that, you know, people, people get to go there and, you know, send you, send you their money so you can have, have more burgers.
[00:22:46] Sara Vieira: More burgers on the table. So that my burgers come from 2 different sources.
[00:22:52] Michael Chan: Diversifying, baby. Oh, so you have um a number of topics that you cover in this book. And I just wanted to kind of like maybe high level on like a couple of them and like, you know, the ones that maybe you have the most most opinions about. Uh but you talk about, I mean, just as a a a teaser for the for the user, you talk about um folder and filing structure. You talk about state management, project starters, um you know, packages, hooks, deployment. That's a big thing that a lot of people have so many questions about. And then just like lingo, like the the words that constantly show up for React that kind of make no sense to anyone who's not in like this this cult of React that we've got going on. Now, one thing that kind of I think I have very strong opinions about and they differ quite a bit from other people is in folder and file structuring. And I thought it'd be fun to maybe talk about that one since, um, you know, I got you on, and uh this is something that we both kind of care a lot about in terms of the longevity of a project. Um, what is- what are some of your like high-level takeaways in the book for like things that you should think about as your projects grow?
[00:24:04] Sara Vieira: Name your components. Because if you use the React DevTools, it's gonna be painful. It's gonna be really painful. Learn how to use the React DevTools. That would be nice. I never- I like- I I I can use them. But like, I don't know, I just do console.log-driven development. It's just the way I was raised and born. But they're really good. I use them today for like- I use them very sparingly. Not the point. Um, uh, so like one thing, I am in the export default ban. Like I name my components and then in general I export them default unless they're like a types file, for example, or they're a utils file, whatever, or they're an action for state or something. If it's a component, I export it default because VS Code knows. There is no need. Like, if you just name your file the same thing you name your ex- your constant, VS Code knows what you're doing.
[00:24:55] Michael Chan: Okay.
[00:24:56] Sara Vieira: So like, you don't really need that, like, export something so that TypeScript or VS Code figures it out. VS Code knows. It's just easier. At least, like, there are some companies that use two components in one file. But I find that weird. Just create another file. I have issues with really long files.
[00:25:16] Michael Chan: Okay. That's interesting.
[00:25:18] Sara Vieira: Yeah, no, I I split everything.
[00:25:21] Michael Chan: Okay. So, you have— so so just so I can kind of like wrap my head around it. It's always kind of hard to like visualize things that we're we're talking about. But but so, in your case, like you would have a a unique file for every component.
[00:25:36] Sara Vieira: Okay, so what I'm working on, I'm working on a dependencies modal, like where you add dependencies or go in sandbox. We're trying to make it like better. Yep. Not faster, 'cause it was really fast, but like so that you can add both and stuff, like 2 dependencies at once. I know, insane. Um, and for example, I have a a modal component, which is not called modal, it's the index. I have an icons, which does export several things, which contains like the GitHub icon, the home icon, whatever. And I have a dependency and I have a footer. Which is the thing that has the button that says add dependency. So this is usually like how I try to structure things. So like it's more by the focus of it. Like this is a dependency, like one of them. So I map it and then it's one dependency. The footer has another thing. So since everything is in the state, you don't in the global state, you don't really need to like pass things around because everything's there. So you can just pick it up.
[00:26:27] Michael Chan: Yeah.
[00:26:29] Sara Vieira: So yeah, that's usually how I do it. It's, yeah, I don't- Interesting.
[00:26:34] Michael Chan: So, so you mentioned, you mentioned naming the components though for the, uh, for the dev tools, right? So you have-
[00:26:41] Sara Vieira: Yeah.
[00:26:41] Michael Chan: So how does that work with like the export default? Like, do you do like export default and then name your component like with, or export default function and then like the name, or do you kind of like name it and then export it separately?
[00:26:53] Sara Vieira: Yeah. Yeah. So for this case, it's like const SearchDependencies and then export default SearchDependencies.
[00:27:00] Michael Chan: Okay, gotcha, gotcha.
[00:27:01] Sara Vieira: Yeah, so it has a name. I just usually, like, in all my years, I don't think- oh, I also have a component for the search box. Um, like, it's very rare. Like, in all of these files, the one that I know I'll have more than one export is the icons. I know there's gonna be more than one icon. Okay. So that makes sense.
[00:27:20] Michael Chan: Yeah.
[00:27:20] Sara Vieira: Otherwise, I just put like const whatever the name is, and then at the bottom, export default.
[00:27:25] Michael Chan: Gotcha.
[00:27:25] Sara Vieira: Which at actually at CodeSandbox, we don't use that, but I do prefer it.
[00:27:29] Michael Chan: Yeah, yeah.
[00:27:30] Sara Vieira: Export everything, uh, like export const @DependencyModalFooter, for example.
[00:27:35] Michael Chan: Now for people who like might not know that this is like what's causing certain, uh, I guess legibility issues in the React DevTools, like what is it that you see when you don't name your component?
[00:27:48] Sara Vieira: Unknown. I think it's unknown.
[00:27:50] Michael Chan: Yeah. It's like, Unknown. And like, does it show up in brackets or something like that?
[00:27:56] Sara Vieira: No, I'm not gonna- we can test that. Yeah,
[00:27:58] Michael Chan: we, we should.
[00:28:00] Sara Vieira: No, it's not open anymore. I mean, I'm sure there's at least one of, one of them that doesn't have one. Yeah.
[00:28:05] Michael Chan: This is something that like is always kind of, uh, I don't know. I know I've, I've like run into that. I was like, unknown, like surely it's known, like the co- it's rendering a component. How can it render an unknown component? Um, it's that bit, it's that same kind of like language is like destroy is not a function or whatever it was.
[00:28:22] Sara Vieira: Yeah. It says anonymous.
[00:28:23] Michael Chan: Anonymous. That's it.
[00:28:24] Sara Vieira: Yeah. It says anonymous. Yeah. We have a route and then anonymous helmet and then editor. Yeah. It's anonymous, which I'm like, what, what is this? Then you just click it and you're like, oh, great. But also there's the problem of when you actually have an error in the console, it also says like, unless you have it really well set up, it will say anonymous component basically. It won't say like this was caused in the add dependency component will say this was caused in the anonymous component or something.
[00:28:51] Michael Chan: Anonymous component, which is like totally unhelpful.
[00:28:53] Sara Vieira: Yeah. But I mean, you can fix it.
[00:28:55] Michael Chan: Yeah. Yeah. Yeah. Okay, cool. Well, I think that's a good tip because I think that one of the, the reasons that, you know, people don't, you know, build, uh, like a habit around like the, the, the React DevTools is because a lot of times it can feel unhelpful because of all the patterns that we've kind of accumulated of like export default without naming our functions. Yeah. And so you, you look at that and you're like, well, I can't find what I'm looking for anyway. So like, why would I use this over just, you know, console.log and, uh, you know, where I, where I know exactly where I'm at.
[00:29:25] Sara Vieira: So another thing that I like, you can also do in the React DevTools, I think, is add something that like, um, wait, where is that? Actually, I don't think you can. I mean, you can find a way to do it, but remove all fucking providers. Yeah. You can run name matches and includes provider.
[00:29:44] Michael Chan: Yeah, yeah, yeah, yeah. I, you know, I honestly, I feel like they, they missed an opportunity to call it remove all fucking providers because-
[00:29:51] Sara Vieira: Fuck your providers, son. And it's like boundaries and stuff like that. Like you can actually, like, it's really cool that you can like, uh, hide components when name matches and then a regular expression.
[00:30:05] Michael Chan: Yes. Yeah, yeah, yeah.
[00:30:06] Sara Vieira: Yeah. So you can actually do all sorts of stuff, which is really cool. And you can also show all stuff that's divs and stuff. Stuff, so that's nice.
[00:30:12] Michael Chan: Right. Like you can hide or show just the host elements, which can be really nice. Yeah. You know, depending on like, if you're doing like a design thing or you're doing more of a coding thing, you can kind of get those in or out of that tree as needed.
[00:30:24] Sara Vieira: Yeah. Yeah. It's really nice. It's just like, I think it takes a while to get used to like keep using it. Like my wife really uses it a lot and I respect her for that. Um, oh my God, there's so many providers. It's insane.
[00:30:37] Michael Chan: You're like, but console.log for me, honey, just all day. That's-
[00:30:40] Sara Vieira: All day, all day, every day. Console.log. Oh my God. Does it ever happen? To you? I don't know, maybe it only happens to me. But I'm like running Next.js or something and I console.log something and I'm like, why is this not showing up?
[00:30:50] Michael Chan: Oh,
[00:30:51] Sara Vieira: why don't I see my console.log? Because it's in a fucking terminal because it runs in the server. You're like, I am such an idiot.
[00:30:58] Michael Chan: Yes. No, I've I've I've I've done that a time or two for sure. I'm not above it. I'm not above it.
[00:31:07] Sara Vieira: Stupid, stupid.
[00:31:09] Michael Chan: And this is exactly why you should use the React uh DevTools and not console.log Like like us, who are just failing at life right now.
[00:31:18] Sara Vieira: Completely. Like so much time wasted staring at the console and being like, why is Next not logging me?
[00:31:24] Michael Chan: Oh, absolutely. Um, so now this is gonna— like I I feel like we should just uh just just go into it. But like state management. I mean, it's it's been just heartache from the beginning, right? Like as soon as like as soon as Flux came out, to like today, this has just been something that's just been plaguing React developers, new and old alike, or seasoned- sorry, new and seasoned React developers alike.
[00:31:52] Sara Vieira: I feel like I'm both.
[00:31:54] Michael Chan: Um, and so I'm kind of curious, like, what, like, like, what are your big takeaways on like, like the state of state management in 2020?
[00:32:03] Sara Vieira: I feel like, okay, so my first idea is that with a lot of things you can get away with context. Because I heard someone say that like context is not a state management tool, which is true, but it has values that you can set, which is then makes it a state management tool. Pointless. Uh, I think context is something that you can get around with if you just like- but you have to make it a state management tool by yourself.
[00:32:29] Michael Chan: Sure.
[00:32:30] Sara Vieira: Kind of, because like, like, like this person said, I don't remember who it was, it's not a state management tool, it's basically local storage.
[00:32:37] Michael Chan: Sure. So you'd have, but like you'd be using something like, uh, you know, pairing it with either useState or like useReducer, right?
[00:32:42] Sara Vieira: Yeah, exactly. So you have to create a component for it and blah, blah, blah, which is why there's so many libraries about useContext. Like not libraries about useContext, but a lot of libraries that just build upon this because we all end up building our own small little library because we just wanna use context. We don't wanna use something else. And in general, honestly, if your project is like mid-size, so like if you have 2, 3 stores, I would say it's fine. I mean, depending on how big your store is, obviously. Like,
[00:33:10] Michael Chan: okay,
[00:33:10] Sara Vieira: like, I would say like 2, 3 is usually fine. After that, it's gonna be pain in the ass. Sure. To manage things. So like, we, we and my side projects, if I'm ever doing something, I, uh, I usually use something called Overmind.
[00:33:26] Michael Chan: Okay.
[00:33:26] Sara Vieira: Which is made by one of the- we actually hired this person, his name is uh Kristian Alfoni, uh is this really nice, amazing Norwegian man that works at Good Sign Box. And the thing about, like, the thing about, uh, Overmind that I really like and that a lot of people may not like, and it's something that I say upfront, is like, this is mutable. If you don't like mutable, please carry on.
[00:33:51] Michael Chan: Oh, interesting.
[00:33:52] Sara Vieira: I think that he's doing the work behind the scenes so you can make it mutable. And that's the reality of it. It's like Vue isn't actually mutable. It just does the work behind the scenes. So it kind of looks like it is. Um, and that's like, I think state management should be easy.
[00:34:13] Michael Chan: Yeah.
[00:34:14] Sara Vieira: That's my lesson. That's my takeaway. It's like, and this state management is like, I can say state.workspace.dependencies equals like an array and I just push to it or concat to it. Sorry.
[00:34:28] Michael Chan: Right.
[00:34:28] Sara Vieira: And that's it. Like, I don't have to worry about anything else. And it tracks the changes down the tree and it only renders the components I need to like re-render. And it's just like, you're in the view, you call an action, the action changes the state and then it re-renders. Like there's 3 steps and they're very like easy to spot. And I just think like it's so beautiful and like that I, I actually know where files are.
[00:34:57] Michael Chan: Yeah. I think it's beautiful. Well, this is interesting because, because Immer has, uh, Immer has kind of a similar philosophy, right? Which is like, it's much easier to think about things. And Immer's not a state management library.
[00:35:10] Sara Vieira: It's a helper for a lot of these like non-mutable stuff.
[00:35:13] Michael Chan: Right. And it, it does like the immutable work for you, but you get to say like, kind of like push and use all of those APIs that feel like you're actually like doing something or like saying like, do this thing that I need to be done instead of having to like open up all of these like new objects and spread everything all over, you know, to make sure that your new object has all of the same stuff as the old one, but you know, plus these changes. Um, so it's really fascinating to me that there's this like, immutability is something that we want and we strive for in our React apps. But like, it's also a pain in the ass and it's a lot easier to think about things from like an immutable way.
[00:35:51] Sara Vieira: Definitely. Like that's, I think that's what I've learned from using Overmind is that like, I find it so much easier. It's like the website says, making you a happier and more productive developer.
[00:36:03] Michael Chan: Interesting. I'll have to, I'll have to check that out because I really enjoy the philosophy of Immer, um, you know, where I'm able to, where I'm able to use it. So it'd be fun to kind of explore. That is like a state management, state management tool.
[00:36:16] Sara Vieira: It also, like, if you use TypeScript, it's like, it does all the typing for you.
[00:36:20] Michael Chan: Oh, nice.
[00:36:21] Sara Vieira: So when you write, like, for example, you have state.app. I don't know, state.app. I don't know. Sounds like the perfect state you will ever have. Um, if you type state., it will actually just show you everything that you have in the state, like all the stores. And it does that for everything.
[00:36:38] Michael Chan: Nice.
[00:36:40] Sara Vieira: Yeah, it's really good. It's like, honestly, it's the best state management I've used in a long-ass time.
[00:36:46] Michael Chan: Interesting. I had not up to this point heard of it, so I'm grateful that you gave me something new to play with. Maybe we'll have to have uh Cristian on the show too to talk about it.
[00:36:57] Sara Vieira: Oh yeah, definitely get Cristian on the show.
[00:36:59] Michael Chan: Yeah, that'd be super fun.
[00:37:00] Sara Vieira: He's such a nice guy. The Nordics are the best.
[00:37:06] Michael Chan: I can't say that I know many many Nor- Nordics.
[00:37:09] Sara Vieira: I mean, they don't leave. It's a great place to live. Oh, it also supports state machines and GraphQL, by the way.
[00:37:16] Michael Chan: What? Yeah. What? This is like the perfect thing. I'm I'm definitely checking this thing out.
[00:37:21] Sara Vieira: Yeah, it supports state machines and it also supports GraphQL. And it is SSR as well.
[00:37:27] Michael Chan: Nice.
[00:37:28] Sara Vieira: Yeah, it has one add-on for GraphQL and one for state machines. That's the add-on for GraphQL is actually what we use to make GraphQL in CodeSandbox because it's way more maintainable. Oh, sweet. Yeah. Nice.
[00:37:37] Michael Chan: Now you mentioned, you mentioned kind of, you know, working in Next and I don't, uh, CodeSandbox isn't built on Next, is it?
[00:37:44] Sara Vieira: Oh, sorry. No, this is the website for my book.
[00:37:46] Michael Chan: Okay, cool. No, perfect. Yeah. Yeah. No, so you mentioned working in Next and the console.log thing, which brings us to kind of this like starters, right? Yeah. And I mean, it feels like there's so many starters, but it feels like, like kind of like Gatsby, Next. Um, have kind of like domin- and, and React, uh, Create React App have kind of like dominated the space. I'm kind of curious, do you have boundaries for like when you recommend each to people or like, like steer clear of this one or that one?
[00:38:14] Sara Vieira: I usually don't recommend Gatsby or, um, sorry, Next to anyone who's starting out. Mm-hmm. Because there is like, you're not, first of all, they're like, when one of them is not SSR, but it has the same idea of like So there's no window and that can start to get really confusing.
[00:38:32] Michael Chan: Sure.
[00:38:33] Sara Vieira: The fact that it runs on the server and then the client and also in Gatsby, I think the GraphQL part can get a bit confusing if you don't know GraphQL. Like the reason I got into Gatsby like super fast because I already knew GraphQL. So like, it was just like, oh, this makes perfect sense. But to someone who doesn't know GraphQL, they're like, what the fuck is this?
[00:38:55] Michael Chan: Yeah, it's-
[00:38:55] Sara Vieira: Why though? Por qué? Por qué?
[00:38:58] Michael Chan: GraphQL- sorry, Gatsby is definitely like a, I want to get better at, or I already know GraphQL, like the framework for that type of person.
[00:39:09] Sara Vieira: Yeah, basically. Yeah. And I think Next is like easy to use for something that's SSR, but it's still SSR and it takes a bit of a learning curve.
[00:39:17] Michael Chan: Yeah, because especially now it seems like they've broken out like the server-side functions and the like client-side functions. So you kind of have to-
[00:39:24] Sara Vieira: Oh my God, no, I love these /api routes though. That's great.
[00:39:27] Michael Chan: Oh yeah, yeah, absolutely. I think it makes- I love it. Um, it makes it makes sense if you're familiar with the fact that this is rendering in two different environments.
[00:39:39] Sara Vieira: Exactly. Yeah. So there's a lot of like thinking that needs to go behind it that you may not, you may have or you may not have. So that's my main- it also like a lot of it depends on like Uh, does it matter? Like it didn't make- it didn't matter at all if we use Next in CodeSandbox. It's like,
[00:39:57] Michael Chan: sure,
[00:39:58] Sara Vieira: you wouldn't be able to load a lot of it in the window, so you would just like slightly look faster, but like it does make sense in the homepage or in the docs.
[00:40:05] Michael Chan: Yes.
[00:40:05] Sara Vieira: Because you want to Google that. So like, and there we use Gatsby, but that's the same idea. It's like, does it matter?
[00:40:12] Michael Chan: Yeah. And now just, just for, to be thorough, like. Create React App doesn't have any type of SSR concept in it right now.
[00:40:22] Sara Vieira: No. Yes. No. Wait, that was stupid. I mean, because I said yes, no, it doesn't have any concept. Yes. No.
[00:40:30] Michael Chan: Yes. No, it doesn't.
[00:40:32] Sara Vieira: No, it does not have any concept. It does have the concept of a service worker. Okay, cool. That's about it.
[00:40:38] Michael Chan: Now that is- Create React App is actually like the basis of the React project in CodeSandbox, right?
[00:40:45] Sara Vieira: Yeah.
[00:40:46] Michael Chan: Cool.
[00:40:46] Sara Vieira: It's like a very slimmed down version of Create React App.
[00:40:49] Michael Chan: Yeah. And this is like, I, I agree with you wholeheartedly that Create React App definitely seems like the best way to like get into it. And part of that is because of CodeSandbox where you can like click a button and now you have a React app in a browser. You didn't have to set up, you don't have to like know anything about Node or whatever. If you just wanna like build something using React or go through the docs, Like this is hands down the easiest. You got like, you gotta log in and then you like press a button and like now you have a React app.
[00:41:17] Sara Vieira: Yes. Also for Vue. Like I'm just saying, or Gatsby.
[00:41:20] Michael Chan: Yeah, that's right. We gotta get that, we gotta get that CodeSandbox chatter going for you. So yeah, like Vue, Gatsby, Vanilla. Do you have a Reason one?
[00:41:32] Sara Vieira: Yes, but I think it's really outdated, so let's not talk about it.
[00:41:36] Michael Chan: Okay. Okay. Okay. We'll take it out.
[00:41:37] Sara Vieira: We'll cut it out. Yeah. I do think that like, not just CodeSandbox, but a lot of these tools like CodePen as well, and all a lot of them like really help people getting started because I think a lot of the things are issues with like kind of fear of the command line. Like it's kind of scary.
[00:41:52] Michael Chan: Yeah.
[00:41:53] Sara Vieira: Like I once deleted an entire like operating system. I added a space between dot and slash.
[00:42:02] Michael Chan: Oh yeah, that'll get you.
[00:42:03] Sara Vieira: There was a space there, Michael, and that was it. That was the doom of me. Yeah. Linux machines.
[00:42:11] Michael Chan: They're very unforgiving. They're like, yeah, you know what you're doing.
[00:42:15] Sara Vieira: Yeah, you want to delete the entire operating system, right? Yeah, sure.
[00:42:18] Michael Chan: Sure, yeah, okay, cool, whatever.
[00:42:20] Sara Vieira: And then it started failing midway through because it didn't have the command for rm.
[00:42:24] Michael Chan: Right, of course.
[00:42:25] Sara Vieira: But yeah, like they're scary and they're really easy to screw up. So like, I think all of these tools really like help, to be honest. Like, I wish I had these tools when I started.
[00:42:38] Michael Chan: Yeah. Yeah. Yeah. Well, I mean, I remember trying to get into Ruby on Rails for like, as a new developer. Right. And I was like, okay, I'm gonna try to get into Rails. Like, this is the future. Like, this is gonna be awesome. And I just, I couldn't set up my environment. Like, I couldn't do it. Like, I, I understood kind of the concepts of like what Rails was trying to do and like, once I got it going, like how it would work and what I would do to build an app, but Like I couldn't for the life of me get an environment set up and like, this can be so demoralizing when all you wanna do is like learn this new thing. And, um, that's what I love about the work that you're doing at CodeSandbox, cuz it actually lets people do that instead of focusing on the, the bullshit just to get to the place that you can do it.
[00:43:21] Sara Vieira: Yeah. I don't remember. I don't know if you remember, but like 2 years ago or something, I made a website that was like, uh, what, what was the name of the website? Make Frontend Shit Again.
[00:43:31] Michael Chan: Yeah, yeah, yeah, yeah.
[00:43:32] Sara Vieira: Do you know why that website was made? Because I went to this thing, I went to- was helping a couple of friends of mine that made ReasonCon. I was helping them with like, you know, just putting mics on people and stuff like that. Yeah. And the next day there was a Reason workshop, so I was like, I'm gonna do this. Couldn't get fucking Reason up and running in my computer. I got so mad. I got like- I was just like, I was so frustrated that I made that website. Because I couldn't get it to work. Like, I, I, for the life of me, I spent like 3 hours trying to get Reason to work on my machine and it would not work.
[00:44:03] Michael Chan: Yeah, it's very frustrating. And like a lot of times it's like people don't know how to help you. It's like, oh yeah, well it should have worked. So sorry, I guess.
[00:44:11] Sara Vieira: The issue is like, I had an issue on my old computer where for some reason, if I run npm i/g, like Lodash, like Lodash is not a good example, but like Netlify CLI, for example.
[00:44:22] Michael Chan: Sure.
[00:44:23] Sara Vieira: And then I ran Netlify CLI, it'd be like, I don't know what this is. And I'm like, what? And like, 5% of the times it would work for some reason. And all the other percent of the times I had to be like, npx netlify-cli login, because for some reason it just didn't work. So like, if you, if you, if you told me like, you have to install this globally, I'm like, yep, not that. Yeah, I'm done.
[00:44:46] Michael Chan: Maybe you had an extraneous space and it was, you know, rm and RMing your operating system.
[00:44:51] Sara Vieira: You just need to know that I'm very lazy. I never fixed it, but I got a new computer, so that's fixed, I guess.
[00:44:56] Michael Chan: I like this idea that you just get a new computer every time you nuke your operating system.
[00:45:00] Sara Vieira: I bricked it.
[00:45:03] Michael Chan: Hey, this one's done. I need another.
[00:45:07] Sara Vieira: No, it was just- it was getting super slow. It was really old. It was kind of old. It was like 3 years old or something, and for running like a thing like God's Sandbox which sometimes you have to run the backend with Docker and everything. It turned out pretty well 'cause I started learning Blender and kind of needed a new computer.
[00:45:22] Michael Chan: Nice. Nice.
[00:45:23] Sara Vieira: So, but yeah.
[00:45:25] Michael Chan: Now, now one thing that's fun about actually working, um, in CodeSandbox is, is that you get those URLs. So like, you know, like you, you make something and now it's like you actually have a website that you could like point people to. Um, which kind of brings us to the notion of like deployment. That is super tricky for a lot of people. And like, what are the, like, what are a couple things that you recommend for people who wanna like actually take it you know, from, you know, just their local environment to, you know, a production thing.
[00:45:49] Sara Vieira: For the- like, use Netlify or Zeit.
[00:45:52] Michael Chan: All day, Netlify or Zeit.
[00:45:55] Sara Vieira: But I am dead serious. I had never deployed anything to the internet until Zeit, I think. Like, I had like a personal website that I FTP the fuck out of, but like the actual first- like, I didn't deploy pretty much anything until Zeit came out.
[00:46:10] Michael Chan: That's what we're putting on your shirt. FTP the fuck out.
[00:46:13] Sara Vieira: FTP the fuck out of that website. Um, oh my God, I just love it. I love FTP. Sometimes I miss it. I'm just saying. But
[00:46:21] Michael Chan: oh, same, hard same. Yeah, I get super nostalgic.
[00:46:24] Sara Vieira: It's so easy.
[00:46:25] Michael Chan: Yeah, yeah, yeah, absolutely.
[00:46:27] Sara Vieira: But then you had to fix a bug and it was so much harder.
[00:46:31] Michael Chan: Yeah, you can just take your whole, whole, whole site down real quick.
[00:46:34] Sara Vieira: Yeah, real fast, man. wp-config badly copied.
[00:46:37] Michael Chan: There's no CI for FTP.
[00:46:39] Sara Vieira: That's it, million-dollar idea. CI for FTP.
[00:46:43] Michael Chan: Oh shit!
[00:46:44] Sara Vieira: When you drag a file, it runs CI on that file.
[00:46:48] Michael Chan: Oh man, this is- this is- this is how we make our burger money.
[00:46:52] Sara Vieira: I know, right? I know. One day we'll have pasta money, I'm telling you. Italian dinner money. Um, uh, I have no idea what I was saying.
[00:47:04] Michael Chan: I don't either.
[00:47:05] Sara Vieira: But yeah. React. Oh yeah. Wait, no. Oh, deployment. Yeah. Zitonix. Seriously. Like if you just wanna deploy something static, like you can just literally drag things into Netlify.
[00:47:18] Michael Chan: Yeah.
[00:47:18] Sara Vieira: Like this is mind-blowing to me that I can just drag something and it's on the internet.
[00:47:23] Michael Chan: Yeah. That's, that it's like, if you haven't had like worked in an environment where you have like a nice, like CI/CD pipeline. Yeah. Going to Netlify and like, just like logging in, connecting it to your GitHub is like, holy shit. Like, where's the, like all of this magic coming from that's putting all of this stuff together? Cuz it's amazing and I love it.
[00:47:42] Sara Vieira: And some, it's amazing. Yeah. So I would say just like, site or Netlify, to be honest. Like if you wanna run SSR, like you have to use, you have to use site. Like there are ways, but in general you have to use site. Yeah. But like if you're running something static, just like take your pick. They're both great.
[00:47:57] Michael Chan: Yeah.
[00:47:58] Sara Vieira: It's just like, what? I can just drag something? Like, I do think that Zeit is slightly more technical than Netlify, so it kind of depends on where you stand.
[00:48:06] Michael Chan: Sure.
[00:48:07] Sara Vieira: Um, but yeah, like on both of them, you can deploy something in 5 minutes and that's insane.
[00:48:12] Michael Chan: Yeah, it really is. Do
[00:48:14] Sara Vieira: you know how long my like entire website uh for the Opinionated Guy takes to deploy? 52 seconds.
[00:48:21] Michael Chan: Oof, that's good. That's good.
[00:48:23] Sara Vieira: What the fuck?
[00:48:24] Michael Chan: I'm not even like ready to like switch over and like look at production after 52 seconds. I'm like still snacking at that point from like the hard work that I did.
[00:48:32] Sara Vieira: Same, same. I'm just like, it's done. It's still pushing in my machine, you know, 'cause internet's shit. But on the other side, it's already live.
[00:48:39] Michael Chan: Oh, hey, before we um kind of like close things up, I I just wanted to ask you like kind of how you're building your book. 'Cause I know you're you're self-publishing all this stuff and um you know I wanna direct people back to this book. Because I think that it's gonna help so many people, whether or not they're like new on the React journey or kind of want to gain the experience that you've gained building a, a really big application like CodeSandbox to get this book. But I'm curious, like how you actually made it. 'Cause, uh, you know, you're, you're a programmer. I'm sure that you probably did something fun. So what does it look like behind the scenes?
[00:49:15] Sara Vieira: So basically I made a Gatsby website that renders a gigantic Markdown file.
[00:49:20] Michael Chan: Okay.
[00:49:21] Sara Vieira: And from that- no, wait, there's, there's a continuation to this. From that-
[00:49:25] Michael Chan: No, I'm excited.
[00:49:26] Sara Vieira: Exactly. I have like a print stylesheet and then I use Puppeteer to get the, uh, the PDFs for that, which makes it easy for me to have like light and dark versions because they're just props I pass to the top of it. So if you go there and if you go to the localhost that I have and you just pass in theme equals dark, it will render the dark version. And, um, what? Yeah. And then it, it gives you back a PDF, like all compiled and everything. You can add a cover and everything. I use, uh, let me just open the thing because I don't remember the name of the actual package because I know, you know, that's, that's how we live. We just use these things.
[00:50:02] Michael Chan: Fast and loose, putting spaces where they don't belong.
[00:50:05] Sara Vieira: Uh, PDFLib. It allows you to create, modify, like I even added, you can add the the folder, the the COVID and I even added a second page as like a dedication and stuff. You can do like pretty much everything. So-
[00:50:17] Michael Chan: Wow.
[00:50:18] Sara Vieira: Basically what it does is that it gets the- Puppeteer opens the browser, takes a huge-ass PDF, and you can add a margin to Puppeteer and you can add header and footer templates. I don't have anything in the header, but I have the number in the footer. And then the PDF document just loads the book and you can add whatever you want to it. And it's beautiful. And then I I also have uh epubgen, which gets HTML files. And turns them into EPUBs.
[00:50:45] Michael Chan: Okay.
[00:50:46] Sara Vieira: Yeah, and Calibre does- Calibre is a free application. Like, I used to use um something called Kindle Previewer, but turns out that didn't work very well. So now I use Calibre to make it from EPUB to MOBI, which is for for Kindles.
[00:51:00] Michael Chan: Interesting. So like you so you go this route and like now it's like super easy. Like like I know that you have like a preview on your website of like if someone wanted to kind of preview what it looked like or like what a chapter might cover. So, it's like super easy then to just like go through and like just pick out a couple pages and generate that.
[00:51:16] Sara Vieira: Yeah. It's literally yarn generate book. And it it generates the uh EPUB, the dark version, and the light version. And then all I have I have to go to Calibre and make it into a MOBI file. That's it.
[00:51:29] Michael Chan: That is amazing. I love that.
[00:51:32] Sara Vieira: It's like it works pretty well. It's like it's one of those things that you're like, that's never gonna work. And then it works. And you're like, you mean I can just do this?
[00:51:40] Michael Chan: Yeah. Wow. I'm just, I'm just making a webpage that happens to turn into a book.
[00:51:44] Sara Vieira: Yeah, that's literally it. So I did open source this, it needs to be updated, but I did open source like 90% of what it's here. So I'm just gonna, I'm gonna update it and oh, you can also add CSS to the EPUB by the way.
[00:51:58] Michael Chan: Nice. Nice. What is, um, what's the name of your package for it?
[00:52:02] Sara Vieira: It's gatsby-starter-book. That's literally it. And then it has, yeah. So I think it's missing stuff for like the, uh, uh, chapter creation for the EPUB.
[00:52:13] Michael Chan: Okay.
[00:52:13] Sara Vieira: And it's missing the dark version. That's about it that I need to add to it.
[00:52:17] Michael Chan: I love it. That's, that's very exciting. I'm gonna have to check this out. Cause I've like, I've always thought it'd be fun to like make a book. I mean, just to say that I did it, even if it's just like a shit book. Um, and so like maybe this would, maybe this would be the tool that I need to just kind of get over the-
[00:52:32] Sara Vieira: It's a Markdown file, man.
[00:52:33] Michael Chan: Yeah.
[00:52:33] Sara Vieira: If you wanna use MDX, you can also use MDX. I just used Markdown because I didn't have any React components. I think I'm gonna add one, but yeah, it's just Markdown that renders into a page with Gatsby.
[00:52:43] Michael Chan: I freaking love it. I freaking love it.
[00:52:45] Sara Vieira: It was actually an idea from a friend of mine here, uh, that also wrote a book in German. And I was like, how did you make it into a PDF? He was like, Puppeteer. And I was like, what?
[00:52:55] Michael Chan: Dude, Puppeteer is the magic.
[00:52:57] Sara Vieira: You're such a smart boy. Wow.
[00:53:00] Michael Chan: It's true. That is one of those technologies where I feel like if I could, like, I'd be winning if I had a really strong grasp of Puppeteer.
[00:53:08] Sara Vieira: You know what's weird that I'm getting a huge grasp on in my life is Cheerio. I don't know if you know Cheerio.
[00:53:14] Michael Chan: Oh yeah!
[00:53:14] Sara Vieira: It's jQuery for Node and I'm like, I'm like, I understand this now. Like, I don't know why, but I keep having to go back to it, like, for some reason.
[00:53:23] Michael Chan: Oh, totally, yeah.
[00:53:25] Sara Vieira: People keep sending me HTML strings. I don't know why.
[00:53:28] Michael Chan: Oh man, yeah, I used Cheerio Heavily when I was like doing our um icon stuff with uh SVG manipulation.
[00:53:36] Sara Vieira: Um yeah. Yeah. And it works great.
[00:53:38] Michael Chan: It works great. Chirio is amazing.
[00:53:40] Sara Vieira: It's the best thing. Like it's insane how many times I've used this. It's insane. Like for everything. It's insane.
[00:53:47] Michael Chan: Yeah. It's funny. Like you say like jQuery for Node and you're like, that is stupid, but no, it's awesome.
[00:53:53] Sara Vieira: It's awesome. I love Chirio. It's great. It's just great.
[00:53:58] Michael Chan: Well, hey, I could talk to you all day, all night, but I know it's getting kind of late in your time zone and, uh-
[00:54:04] Sara Vieira: Can I just say something?
[00:54:05] Michael Chan: Yeah.
[00:54:06] Sara Vieira: Just one thing real fast is that I I I added, I don't, you can't see it from where you are, but I added uh purchase parity power on the website and that I want to tell people how I did that because I think it's important that we kind of start doing that, like start realizing that things don't cost the same in every place.
[00:54:26] Michael Chan: Oh yeah, yeah, yeah, definitely. So tell me a little bit more about the idea. I'm not familiar with the purchase parity power concept.
[00:54:33] Sara Vieira: Oh, so uh purchase parity power means like something- $10 is not the same in the US as it is in India, for example. Like someone-
[00:54:41] Michael Chan: Gotcha.
[00:54:41] Sara Vieira: Yeah, it's just the cost of living in a place and how much money the person makes. Like $10 for you is not a lot, like $10 in the US is not a lot. Well, €10 in Portugal, like in for 2 days.
[00:54:51] Michael Chan: Yeah.
[00:54:52] Sara Vieira: Okay, 1 day, lunch and dinner. Um, so like, it depends a lot on where you're from. And and the thing is, like, there's not a lot of open information about this. But one thing that you can do, and I'm not sure a lot of people know about this, and I found out this by accident because I moved and then started paying more, is Spotify does not charge you the same whatever country you're in. Spotify actually does parity purchasing power. I used to pay 6.99, now I pay 9.99. From Portugal to uh Germany. So you can get the Spotify prices and do it yourself, and it's great. And I think like we kind of like need to start- it's something that I think- okay, so that's the thing. If I sold my book for $30 in India, no one would buy it. Sure. And if they did, I would honestly feel terrible about it. So it's like, I think it's like $7 with the purchase, which I- it doesn't make me feel like shit. So like, I think that we all need to kind of like realize that things don't have the same price everywhere. And that just because it's cheap for you doesn't mean it's cheap for everyone. Like $40 may not be a lot for me now.
[00:56:06] Michael Chan: Right.
[00:56:06] Sara Vieira: But if you told like 19-year-old Sarah, she would be like, I don't have $40. Like, I don't know what you're talking about. I don't have a credit card.
[00:56:13] Michael Chan: Yeah. And, and I mean, it makes a big difference. Too. It's like, you know, a lot of, a lot of developer content is priced for not even the individual buying it, but the company buying it through some kind of, you know, like continued education stipend. So it's like, oh yeah, it's like, you know, $150. Like, that's cool. Like, my company's gonna pay for it.
[00:56:33] Sara Vieira: Exactly. And that's like- so what I wanted to do was build a book that I'm never- I don't think I'm gonna get rich with this book in any way. I also don't know what's the threshold for rich in Germany, I have no fucking clue. Uh, is it like, it's Merkel level, it's like chancellor level, that's when you're rich. Um, no, it's when you have a personal German speaker, you know, that you can just call and they'll go with you somewhere. But, uh, but my idea was that I think a lot of these pricings, as someone who has a full-time job, need to also be done, taken in consideration, like how much people can spend as an individual. And not assuming that everyone is in a company kind of. And like, and that company can afford it. Like there's also a bunch of people that are freelancers. Like people have their own company. Like I technically have my own company.
[00:57:24] Michael Chan: Yeah.
[00:57:25] Sara Vieira: Yeah.
[00:57:25] Michael Chan: Well, I love that. I love that notion. I, I, to be honest, I was completely naive of it until you mentioned it right now. So I appreciate you kind of expanding my mind to think about that. How did you actually implement this? Cause I mean, you've done everything for actually implementing this book. And I'm curious, like how do you actually change that pricing based on geography and whatnot?
[00:57:44] Sara Vieira: So I use- that's most of the reason why I use Next.js actually for the getInitialProps thing.
[00:57:49] Michael Chan: Okay.
[00:57:50] Sara Vieira: It goes to an IP address, it goes to an IP service that returns where you're from, which sometimes fails, but it only fails the other way around. Like it gives people discounts they shouldn't have. So I'm like, at least no one's yelling at me. So that's nice. I don't care. I have a full-time job. Um, it'd be worse if there was yelling. Uh, so basically what I did is I crawled all the Spotify websites. But most of it was done- a lot of it was done manually because the Spotify websites uh have the current the price in their own currency.
[00:58:18] Michael Chan: Okay.
[00:58:18] Sara Vieira: So like it's in euros, for example, which then I have to transfer to dollars to get the percentage of how much that is. Gotcha. That part was done automatically, you know, math and JavaScript. And then from there I use Paddle, but I think that's the thing everywhere. You can create coupons through the API. So I made a CLI. I didn't make- I made a- I made a CLI. It was a JS file with like 30 lines, lol. Uh, I made a JS file with 30 lines that basically went through this JSON file that I had and pushed everything as a coupon. And then- Oh, wow. It matched- is the- is the three- so, and I also use the three-letter code from the countries because some of them have two letters and some of them don't have two letters because the two letters are very common. And if the three-letter country matches the one that I get on the IP, you get to show- you get shown the coupon code for your country and you get a banner at the top saying like Hey, I see that you're coming from India, for example. This may be a bit expensive. You can use the code blah blah blah to access- I think they have like 75% discount or something like that.
[00:59:16] Michael Chan: Oh my gosh, I love that.
[00:59:18] Sara Vieira: And I want to say that like it wasn't- it was kind of hard, but I can share all of this. Like, I have all of this data, uh, and I can share all of this data if it helps anyone to put this on their website.
[00:59:34] Michael Chan: Oh, absolutely. I'd love to see it personally. Um, like, about how many discounts did you end up setting up? Like, what- like, like, how many total discounts does this represent? Like, when you account for all the countries that you're discounting for?
[00:59:46] Sara Vieira: I don't know. Let me go to the data. I don't know how many things this has. Also, like, something really bad happened that I felt terrible was that there was a bunch of countries that I assumed had Spotify, and turns out they didn't, so I didn't add them.
[00:59:59] Michael Chan: Oh, interesting.
[01:00:00] Sara Vieira: Yeah, no, they have it now, so it's fine.
[01:00:02] Michael Chan: I think this would be like an amazing resource, and I'd love to link it if we, if we can. Yeah,
[01:00:08] Sara Vieira: I'll create a gist for it. Like, I'll send you, I'll send you a gist for it.
[01:00:12] Michael Chan: Okay, cool.
[01:00:13] Sara Vieira: Uh, uh, coupons. I don't think it says- I have 6 pages of coupons, so it's a lot.
[01:00:18] Michael Chan: Woo! That is a lot.
[01:00:20] Sara Vieira: Yeah, it's a lot. I'm still scrolling.
[01:00:23] Michael Chan: Yeah, well, we'll, we'll link, uh, we'll link what you got, um, because I think that that'll be, you know, super fun to see And, uh, you know, if you're, if you're listening and you can afford the $30, turn that VPN off and buy it for $30 because it's worth your, worth your money as someone who has $30 to spend on React Education.
[01:00:42] Sara Vieira: You know what's the amazing thing? A bunch of people have messaged me saying there was a bug because they got a code they shouldn't have.
[01:00:47] Michael Chan: Oh, nice.
[01:00:48] Sara Vieira: Yeah. Which is insane to me. Like, I was like, a Portuguese person would never do this. No, I'm kidding. But like, it says a lot, I think, about our industry as well, that a lot of people have actually messaged me and they were like, well, this says I'm in South Africa and I'm in the UK. And I was like, that's a weird one, first of all. And there were two people that were not from Poland that were being registered as Polish. And I'm like, what? Uh, turns out Orange in Europe is Polish, so like they all get registered as Polish. Oh well, it's life. But, um, yeah.
[01:01:20] Michael Chan: Cool.
[01:01:20] Sara Vieira: And honestly, if you're from the US or whatever and you can't pay it, Turn on a VPN, like-
[01:01:27] Michael Chan: Yeah.
[01:01:27] Sara Vieira: Not- maybe, maybe, you know, like Portugal or something. I'm kidding.
[01:01:32] Michael Chan: I like how it's like you've got- you can like pick a country based on uh the discount that you want.
[01:01:38] Sara Vieira: Actually, the Portugal one is different from all other discounts.
[01:01:41] Michael Chan: Just because it's like it's it's connected deeply to your heart. This is for your- this is for your fam.
[01:01:47] Sara Vieira: It was literally where I was born, you know, like it's a link in you. No, it's a football one, because like it's our it's our biggest export, you know, Cristiano Ronaldo. That's not the code, but it's about Cristiano Ronaldo. Because you know, that's what we got.
[01:02:01] Michael Chan: That's what you got, that's your claim to fame. Everyone's got everyone's got something. Well, hey, thank you so much for like just talking through the high-level topics of your book. I really hope people will buy it.
[01:02:12] Sara Vieira: I hope people will like it. Like, I really want to hear some feedback, and I hope people will like it.
[01:02:17] Michael Chan: Yeah, get it, read it, let Sarah know what you thought of it. The Opinionated Guide to React at opinionatedreact.com. Do you have a, a, a poenated, uh, react? Like—
[01:02:28] Sara Vieira: No, it's not linking to that one. No, I'm sorry. Sorry to disappoint. I can do that on Namecheap if you want, like real fast.
[01:02:35] Michael Chan: Well, hey, is there anything you want to leave us with today, Sarah?
[01:02:39] Sara Vieira: Uh, no, I think we talked about everything.
[01:02:42] Michael Chan: Sweet. Sweet.
[01:02:43] Sara Vieira: Yeah.
[01:02:44] Michael Chan: Well, hey, it is always a pleasure. Uh, you know, if you have ideas for Sarah's shirt, you know, let us know.
[01:02:49] Sara Vieira: Yes, please let me know. I am super in for that.
[01:02:52] Michael Chan: Just ping us on Twitter because we gotta- you know, she's a, she's a superstar and she gets no reward for it right now, so we gotta, we gotta remedy that.
[01:03:01] Sara Vieira: It's my Lego set. That's my reward.
[01:03:03] Michael Chan: Awesome.
[01:03:05] Sara Vieira: That's about it. Thank you so much for having me. If you do buy my book, please let me know if you liked it or anything you want to see in it. I want to keep building upon it. And also you, Michael, if you see- if you get it, uh, let me know what you- what you would like to see in it, and like, what are the opinions that you think are like just shit, pretty much.
[01:03:24] Michael Chan: Oh yeah, I'm- I'm buying it. I'm buying it right now, full price, $30.
[01:03:27] Sara Vieira: No, dude, I'll send you-
[01:03:29] Michael Chan: No, no, no, no, no, no, no, I can- I-
[01:03:31] Sara Vieira: I'm an adult.
[01:03:31] Michael Chan: No, it's- it's- it's worth it. I- I'm an- I'm an adult. I can- I can do it. I want- I want to support you. We're doing it right now. Live.
[01:03:39] Sara Vieira: I get notifications on my phone when someone buys my book.
[01:03:44] Michael Chan: So you're gonna know if I'm full of shit right now.
[01:03:46] Sara Vieira: Okay, someone bought it in Brazil and Mexico, but that's not you.
[01:03:49] Michael Chan: That's not me, that's not me. Well, hey, Sarah, this is always a pleasure. Uh, I can't wait wait until uh next time when we get to chat again.
[01:03:56] Sara Vieira: Thank you so much for having me, seriously, this has been really fun.
[01:03:59] Michael Chan: Always a pleasure. Thanks, Sarah.
[01:04:01] Sara Vieira: Bye.
[01:04:02] Michael Chan: This has been episode 107 of React Podcast with Sarah Fierro and Chantastic. For links, visit reactpodcast.com/107. Thanks to our sponsor, Infinite Red. If you have a project that's gone off the rails and needs expert help, get Infinite Red on your side. They've been designing, building, and shipping apps for 10 years and want to bring their expertise to your apps, products, and services. They have a deal right now now where you get $750 for referring a new project. Get expert help from Infinite Red at reactpodcast.infinite.red. If you like this show, there's a fast, free way to demonstrate your support. Leave us a review on iTunes. It's the best way for you to let me know what you think we're doing right and what we can improve. 2 to 3 minutes of your time helps us make the best show we possibly can. As always, links and show notes for all episodes are available at reactpodcast.com. This episode was edited by Mikael Delport. It was produced by Mikael Delport and Sarah Jackson at Speck, a network to help you level up in design and development. Check out spec.fm for other shows that are sure to fast-track your career. I'm your friend, Chantastic. Thanks for listening. We'll be in your ears again Next week.
chantastic.fm