-
Notifications
You must be signed in to change notification settings - Fork 0
/
createReactComponent
28 lines (22 loc) · 1.03 KB
/
createReactComponent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//This creates an ES6 class MyComponent which extends the React.Component class.
//So the MyComponent class now has access to many useful React features, such as local state and lifecycle hooks.
// Also notice the MyComponent class has a constructor defined within it that calls super().
//It uses super() to call the constructor of the parent class, in this case React.Component.
//The constructor is a special method used during the initialization of OBJECTS that are created with the CLASS keyword.
//It is best practice to call a component's constructor with super, and pass props to both.
//This makes sure the component is initialized properly. For now, know that it is standard for this code to be included.
//Soon you will see other uses for the constructor as well as props.
class MyComponent extends React.Component {
constructor(props) {
super(props);
}
render() {
// change code below this line
return (
<div>
<h1>Hello React!</h1>
</div>
)
// change code above this line
}
};