React Class Components
March 24, 2020
Class components have state and lifecycle hooks. Thus a component that has a state
property is called a “stateful component” – all class components are stateful.
JSX
x
14
14
1
class App extends React.Component {
2
constructor(props){
3
super(props);
4
this.state = {message : "Welcome!"}; //a state property ==> stateful component
5
}
6
render() {
7
return (
8
<div>
9
<p>My message: {this.state.title}</p>
10
<p>Parent's message: {this.props.message}</p>
11
</div>
12
);
13
}
14
}