Transcript
00:00 Okay. Let's take our user and our product, and we're gonna move them into data. So I'm gonna grab that. We'll go over to the data file, and we'll paste it right there. Now there are a couple ways that we can export this.
00:12 If we just do this, we're not going to have any, any, access to user and data. So here, let's actually export that. There we go. So we're not gonna have user and data. If I save this, we're gonna get an error because user is not defined.
00:28 What do we do? Well, here's what we do. We add an import for user and data, but we're getting an error here because we can't load anything from data because it's not exporting anything. We have to export these. So there are two ways we can do that.
00:42 We can either export right where we're decl we're declaring it, or we can export it here at the bottom. For myself, I typically like to export where it's being declared because, then I don't have to, put it in two places. So here, if we didn't do that, we'd say export user and product, then we get rid of that and get rid of that. And now we have user and product appearing in two places. It's kind of annoying.
01:08 And if we wanted to rename this, then we'd have to use the IDEs functionality, my user or whatever, so that it would rename in both places. And it's it's just a whole it's a whole thing. So I don't wanna do it that way, but you definitely can. But the other thing I wanna mention about this is that, this syntax down here, it looks like an object, But it is not. And if you wanted to, you can actually alias things.
01:31 So here we have my user as user. So we can make this variable my user. And so what what that is saying is internally in this module, this variable is called my user. But externally, where, when people import it, I want them to import it as user. So, we can do the same here for my product.
01:53 And that's exported as product. And that's going to work where we're importing it. So user and product. Tada. That's nice.
02:00 So that's how you alias these things. If you wanna have one name in this file but you want it to be a different name in another file, you use this special as syntax. And that's why this is not an object. These are called export specifiers. So the other thing on the other end of it is what if on this side, you actually wanted to import them as a different name?
02:22 So here, you can actually, import user as my user and product as my product, and then you can call those those things. And that will work as well. You can have it be, my favorite user. However you want it to be, that is how you accomplish that task. And, this is these are called import specifiers, by the way.
02:46 So, the other thing that you can do with this actually is if you wanna say, hey. I actually want all of the things from data. Then you can say import star as, data from data, and then it's, data is actually an object. So if I add here, let's just do a console log data, then we'll see here is, an object that has a product and a user. There's a special time type of an export called a default export, and we'll talk about that soon, which, will have to be called a default on this data.
03:20 So couple ways to import, couple ways to export. Hopefully, you play around with that a little bit and become familiar with it. It's pretty straightforward. Oh, I hope you have a really good time with modules. Now what we finally are able to officially use them.
