00:00In the last lecture we were introduced to props
00:03and how we could use them
00:04to send properties into our component.
00:08In this lecture, we're still in properties,
00:10but this time around we're taking a look at
00:12how do we actually send components into components.
00:15We're gonna basically say, oh, now you are aware
00:18that components could have children just like an HTML
00:22or XML.
00:23We're going to through that understanding,
00:25let's start componentizing our components
00:28and we're gonna learn in E es six how to import
00:30and export classes
00:32and share them to make our code much more reusable.
00:36Moreover than that, we're also gonna learn about object
00:39destruction or disruptors, which is something new
00:41to E ES six that makes really coding so much easier
00:44and it's one of the greatest additions into ES six.
00:47So let's jump into it and let's learn more about components
00:50and a lot more about ES six.
00:55Alright, let's continue making our component even better.
00:58And really our biggest problem in our component right now is
01:02that really outside of the component,
01:04we're just calling a portfolio.
01:06But in reality what's actually happening
01:09is our portfolio itself.
01:11And by the way, I noticed here I have a small type, it's not
01:15Port Folio
01:16but port, port, port, yeah.
01:21Okay, portfolio. There we go.
01:23Um, but it didn't really matter by the way,
01:24because we were exporting this class
01:27and notice what we did inside of the client here.
01:28We redefined the name. We could have called this anything.
01:31We called it call this love.
01:33It really didn't matter
01:34because once it was outside of that package,
01:36that default package could have been called anything
01:39for our case, we called it portfolio.
01:41But literally keeping it the way it is would basically keep
01:44everything looking exactly the same way.
01:46So let's revert it back, let's call it
01:48portfolio 'cause that's what it is.
01:49But really our problem right now, beyond that uh,
01:53spelling error, that was really not an issue.
01:55Our problem is, is that we're baking inside here all
01:58of these elements and in reality we would love
02:00to place them right outside, inside of our client here
02:03so we could then change them whenever we want to.
02:06So the portfolio itself, would it actually bake inside of it
02:10how the portfolio should look like?
02:12It would just have the portfolio functionality.
02:15So before we do that,
02:16I wanna teach you about a new something that is Newt ES six,
02:19which is called destructing.
02:20And with destructing we're gonna get that to happen.
02:23So first of all, let me just, uh, word wrap everything here
02:26'cause I just wanna and let go ahead here
02:28and I want to create here a variable,
02:31I'm just gonna call it creator here.
02:32An object that will mimic the behavior
02:34of this function right now.
02:36So I'm gonna have your A from uh,
02:38and the from is gonna be Ben and I'm gonna have also a two.
02:42And that two is gonna be you. Now wouldn't it be lovely?
02:46And a lot of times when you're working with functions, uh,
02:49it's quite frustrating that sometimes you have to have a lot
02:52of values that just don't have anything inside them,
02:54but only some of the values you need to send.
02:56So for example, if you wanted to send two
02:58but wanted to keep the default here, it would be quite hard
03:01'cause you would have to send that default in or send null
03:04and so on and so forth.
03:05And disruptors are a really wonderful way
03:07to make our code more clean and easier to consume.
03:11Now the way that you work
03:12with a a disruptor, I wanna show it to you.
03:14Basically you create a a a just like the object constraint,
03:18which a curly bracket open
03:20and close one in the variable definition itself there you
03:24say, what are the values you wanna extract?
03:27So there you go. Here we're distracting from and to and
03:30after we destruct, we we want to say,
03:33so whom are we destructing from?
03:35And we could, this is the construct
03:37that will basically take the variable object
03:40and extract out of it or destruct it and turn
03:43and get us only the variables from.
03:45Or two, we could have also said we only want from,
03:47or we only want two or we only want something else.
03:50And if I do your con con log for the from
03:55and two, we should now get those two values separated
03:59and extracted out.
04:00So if uh, we take a look at here, Ben, you beautiful.
04:03So let's continue down this line. Let's see how you do.
04:06You do this inside of a function, which is quite cool
04:08that you could, so you could literally
04:11destruct a function right inside of the definition
04:13of the function itself.
04:15And literally all I'm gonna have
04:17to do here is I'm just gonna, um, there,
04:18there won't be any defaults anymore in our case
04:21and I'm just gonna list out that I want,
04:23although I could have your default.
04:24I want from and I want to.
04:25And if they're not sent in, then those are the values
04:27that would be inside of them.
04:29Now if I go ahead
04:30and instead of uh, um, I'm gonna do a console log
04:35and this time around I'm just gonna go ahead
04:37and I'm gonna send in that object.
04:39So I'm gonna send hey, with our object
04:42and let's also make sure that this is gonna be Ben two
04:45and this should be you two.
04:47And if I go ahead here
04:48and click your honor refresh, we should see
04:51hello from Ben to to you two.
04:54Now if in any, any situation I actually didn't have two,
04:57there is no value there.
04:58It was never created. And let me just comment this out here
05:01because we're not really extracting anything there
05:03and we go back into our application, we're gonna see
05:05that when it re renders itself, it's gonna basically take
05:07that default value.
05:09So we could basically create a default
05:12and also deconstruct it, which makes it really powerful
05:15'cause then we could just send in whatever we want
05:16to without needing to worry about the order
05:19of which it's going to be sent in.
05:21So those are disruptors.
05:23Now with the help of disruptors, we're gonna go ahead
05:25and also implement our portfolio.
05:27'cause we really want to import not only portfolio,
05:30but we also want to import our portfolio item.
05:34Now to import our portfolio item, again, I'm gonna go ahead
05:37and type your export.
05:38And export is gonna make sure
05:40that portfolio item is being exported
05:42but contrary to our default export, which basically means
05:46that our default doesn't have a name.
05:48Really this name is not relevant really
05:50for the sake outside.
05:52Our portfolio doesn't have a name
05:54and we have to explicitly request it to gain access to it.
05:58Now the way we would do it,
05:59and if we don't have here a default,
06:01but I'm gonna keep the default.
06:02If we didn't have the default,
06:04let me just show you how we do this.
06:05Again, we destruct and the portfolio wouldn't be true
06:08because there is no portfolio technically,
06:11although there is it's portfolio,
06:12which is the default as well.
06:14And I'm gonna go ahead here and I could comma
06:17and send out, okay, I want my portfolio item as well.
06:22Now on contrary
06:24to like maybe the portfolio was not called portfolio,
06:27I could also say I want the default
06:29because there is a default
06:31and I could say I want the default as portfolio
06:33or as anything else.
06:35And any value that I send you, I could say
06:37as something else, as item if I wanted to.
06:39But portfolio works perfectly for me.
06:42Now that I have access to portfolio item
06:45and portfolio, I could go ahead now
06:47and extract this portfolio item.
06:49So I'm gonna go ahead and copy that out, save it.
06:52I'm gonna go into my client and I'm gonna open
06:55and close my portfolio.
06:58Lemme just break a few lines so we're not in the edge
07:01of a screen and lemme just make this a little bit cleaner
07:04and we could paste inside our code.
07:07Lemme just push it out a bit. So there we go.
07:09So now we pushed it through.
07:11Now it's not gonna actually run,
07:12but I'm hopefully not gonna get any errors.
07:14So if I run this, so it's going to work,
07:17although it's not gonna show us the portfolio,
07:19why is it not showing us the portfolio?
07:20Because we never really towed the portfolio
07:22that we wanna render anything.
07:23So we need to tell it where we wanna rent those, we
07:26where we wanna render those children.
07:29Now to do that, I'm gonna access the property
07:32of the portfolio as well.
07:34And again, I'm gonna, because I'm doing this inside
07:36of a jsx area, I'm gonna open and close a curly bracket
07:40and I'm gonna type for the variable name,
07:42which is called Vista step props dot children.
07:45And that's all I needed to do to paste inside
07:48of here the children that I want to have inside here.
07:51Going back into my application, I'll see that all
07:54of those children have been created.
07:56Moreover, now I have more control over deciding
08:00what I want in what order.
08:01So now maybe for a certain page I want
08:03to use the same portfolio,
08:05but I'm gonna have a portfolio for X things
08:07and a portfolio for Y things.
08:09So let's say I wanna move the cabin down the line,
08:11so it's not gonna be first anymore.
08:13So now when it re-render,
08:14it's not gonna be first, it's gonna be last.
08:17And there we go. We learned quite a lot of stuff.
08:18We learned how to deconstruct objects as we were looking at
08:22that in our client where we created an object
08:24and then we could de deconstruct it.
08:26Incredibly useful.
08:27We've seen it also how we could use it within functions.
08:30And we've also saw
08:31how we could use those deconstructions in those
08:34exports and imports.
08:36Last but not least, we saw also
08:38that we could export more than one thing.
08:39And by the way, it doesn't have to be a class,
08:41it could be also a function and even a variable.
08:44So we could, whatever we want to export, we could export
08:47and we have only one default.
08:49So if I just went ahead
08:50and I just used just one name inside
08:52of here without deconstruction, I would get
08:54The default value.
08:56So that's it. In this lecture we explored a lot
08:59of e es six things
09:01as we integrated children into our components.
09:04In the next lecture, we're going to move away from,
09:07from components and well, not from components,
09:09but from properties to talk about state.
09:12As we said, there is a difference
09:13between properties and state.
09:15And that's exactly what we'll explore in the next lecture.