3 Minutes with Kent cover art

3 Minutes with Kent

3 Minutes with Kent

Written by: Kent C. Dodds
Listen for free

About this listen

👋 Hi there! I'm Kent C. Dodds (https://twitter.com/kentcdodds). This is a (week)daily podcast where I give 3 minute thoughts about web development. You can subscribe on iTunes here: http://kcd.im/3-mins-itunes and on RSS here: http://kcd.im/3-mins-rssKent C. Dodds
Episodes
  • Prisma is amazing
    Jun 10 2021
    Hey there friends. So yesterday I was just a fanboying I guess about Prisma. If you haven't heard of Prisma, it is a Oh what does that? It's ORN, I can't remember what what the word for that is but it interfaces between you and a backend database. So it supports post-grass and SQLite my sequel and a MongoDB support is coming. So yeah, just so you have a database and you tell it what database what kind of,Database you're hitting and how to connect to it or what the connection URL is. And then it manages connecting to it and you have the rest of your code doesn't have to worry about what type of database it is. You just work with Prisma. And what makes Prisma especially special is that it has a really great way for defining your schema for the types or the models that your database supports. It has a really nice way of making the database match that so it'll create the tables for you and everything. It has a great way for my great.Hitting so if you need to change the column name or something then it will automate that process and and that can be part of your deployment pipeline is to alter tables to add columns and stuff like that. It doesn't quite help you with like breaking changes. It they have some articles to help, you know, how to go about doing that and I have successfully done that with Prisma. But yeah, and and it's it's not like a terribly difficult thing to do necessarily but I mean if it's a really great big breaking change then having zero downtime is tricky. But yeah, I've had a couple like the situations where I needed to remove an enum value and stuff and I was able to do that without too much trouble. Thanks to a lot to prism as migrate feature, but then the thing that you experience on a regular basis working with Prisma that just I love is its type script support. So you define this schema and then it generates TypeScript types. So that as you're using Prisma you say Prisma dot and then the,The table that you want to get and info from and then find many and then you have a select and aware and an order by and if there's relations so like a user has many posts or something then you can get all that users posts or if you're looking for posts, you can get the the author and data from that and it's all just so nice with TypeScript. It's it's brilliant. So if you are using one of those databases and you haven't tried Prisma yet give it a look it is fantastic. I'm really really happy with it. Hope you're having an awesome day andWe'll talk to you later.
    Show More Show Less
    3 mins
  • Using ScriptKit to easily upload images to @cloudinary
    Jun 8 2021
    https://github.com/johnlindquist/kit/discussions/310 https://www.scriptkit.com/ Hello friends. So this morning, I finished something that I was working on a little bit yesterday. It's a script kit script to call Cloud Nary upload which allows me to very easily upload images to my cloud nary account. It uses the cloud nary API and yeah, I just need a couple of environment variables and and you can use this too. You get script kit, you can copy the same script. And yeah, you just need a couple environment variables and then it uses the script kit. UI which is basically kind of like,Spotlight or Alfred where you say I want to run the culinary upload and then it asks you which folder you want to upload it to and it gives you this way to navigate around those so you can say on the current folder. I want one folder one directory yep or I want to go into this directory and so you can kind of navigate the folder structure of cloud nary which is really useful for me because I know that I could just like throw all of my blog post images and all of my epic react article images and all of my other images throughout my site into one giant bucket andReference those URLs and whatever but I don't know about you I just really like to have things organized and directory makes the most sense. And so, you can navigate around the directory as you would expect. You can create a new directory and I also cash the other folders that are within a directory so I don't have to hit the API every time you go you're as your navigating around. And so I give you an option to refresh the cash for a particular directory. And and yeah, and so once you've selected your directory, then it gives you a drag and drop little UI where you can drop as many images.As you like and then it goes through each one of those images and asks you what you want the name of the image to be it gives the default for whatever the file name is And then yeah and then it'll upload it. And when you're all done, it will open up your browser to show you to the directory that you chose so that you can see all the images. It also copies the URL for each image that you uploaded and so if you have if you're just uploading one then that's the one that's in your code board. If you upload multiples and they're gonna overwrite each other, which is why I think it's really good idea to have a clipboard history with Alfred is is how I do that. And so yeah, I just updated.My 2010 decade and review posts in their like 20 images in that post and I uploaded those all of those and updated the blog post in like just five minutes. It was really nice. So eventually, I'm gonna automate the whole process of putting all of my images on cautionary for all my blog posts, but this was a really good first take it what it's gonna be like for writing new blog posts and uploading new images. So anyway, this is another example of where script kit is awesome. I'll put a link to the script in the description and I hope that's interesting and helpful. Have a nice day.
    Show More Show Less
    3 mins
  • Avoid Hasty Abstractions: Hooks edition
    Jun 7 2021
    Hello friends, so I wanted to talk today about whether or not you should make a custom hook for everything. So a few days ago, maybe last week there was this thing going around where people were recommending that you never ever use the react built-in hooks inside of a component, you always extract it to a custom hook. This is terrible advice. Don't do that at all. So the way that I think about hooks in React is the they're basically functions that have the,Only special distinction of being functions that actually call other hooks. That's the only thing special about them. So everything else about this function is the same as regular functions. And you don't make a function for every line of code that you write right? Like that would be ridiculous. The reason that we make functions is to encapsulate certain logic. And most of the time it's useful mostly for reuse. Sometimes it could be nice to take a bunch of chunks of code. And logically put it together so that it can be separate from the rest of our our code, but you've got to keep in mind that every single time you abstract something into another function you're adding complexity. And now you have to pass parameters and and maybe you didn't pass enough and so now you need to update those in the except the additional parameters and and and then if you're doing TypeScript, you have to make sure that you're typing for those parameters is correct and and potentially worry about the return value and then oh what if now weDecide that there's some logic in this function that says never mind let's return early or let's throw an error or something like that. Now, you have to start worrying about the consumer and say, oh well, they wanted to return early from here. So, I'll return early. It just gets to be more complex. There are more things to think about. So you can't avoid adding complexity when you start abstracting things into functions. It's just the way that it is it always adds complexity. Now whether or not it makes your code simple or more simple.Is a different matter or sorry let me say that differently whether or not it makes it easier for you as the the writer of the coder and the maintainer of the code to understand what's going on. That's a different matter. But the fact is that it will always increase complexity to extract things into separate functions and that is no different with hooks. This is especially relevant if you wanted to abstract just the use effect part, but you want to pass in some sort of function that's going to get called within that effect. That means that you'll either need to.Call back that your passing in or you have to use the latest ref pattern to always use the latest function. So anyway, hope that helps.
    Show More Show Less
    3 mins
No reviews yet