- [Instructor] Extends are very simple to understand.
In fact, we've used them already
when we've talked about constructors.
Their use is simple.
When you want to leverage another class
or create your own, you extend it.
If you've ever worked with stateful components
in React, you're familiar with extends.
When you create a stateful component,
you extend a react component class.
Let me show you in our project.
So we're back to the app.js file,
and as you can see, we've already used extends here.
So this is primarily how it's used.
You grab a class here, and you create
a new one, and then you extend the previous class.
So we created the class SUV,
and we're extending the Car class.
That's as simple as it gets.
And you see this all the time when we create
React components, we're extending the React class.
So let's go ahead and create that.
So let's go in the sandbox route directory here,
and create a new file, and we'll call this one react.js.
And what I'm gonna do here is do the usual import
for react, so import React, and then we'll import
a component from react.
Now, you may see some errors here
because we don't have React installed
on this particular project,
this is just for an example.
I just want to show you how React use extends
to extend the component class.
So let's go ahead and create a new component.
So we would create a new component
by doing class, and in this case let's create
a button component, which would extend
the Component class from React.
And then we do the usual stuff,
so now we would do something like render, the render method,
which takes a function, which returns
whatever is the code that we want.
In this case, let's go with a div button,
which is a Hello button or a Click me, or whatever you want.
This is the usual class that you would create
when you create a stateful component inside
of a React application.
And then all you would need to do is export default Button.
And this is how React uses extends.
So, basically what we're doing, we're importing
the Component class from the React Library
and then we're creating a new class,
which is our new component.
Again, this is a stateful component
where we extend the Component class
and create our component, which is right now a button.
So, you will see this all the time
and everywhere in your react applications.
So if you really want to practice how
to use classes and extend them
and do a whole bunch of stuff related to classes
like Super, Constructor, things like that,
then create React applications with components,
and you will get a lot of practice there.