1class Car extends React.Component {
2 constructor(props) {
3 super(props);
4 this.state = {
5 brand: "BMW",
6 color: "Black"
7 };
8 }
9
10 changeColor() {
11 this.setState(prevState => {
12 return { color: "Red" };
13 });
14 }
15
16 render() {
17 return (
18 <div>
19 <button onClick={() => this.changeColor()}>Change Color</button>
20 <p>{this.state.color}</p>
21 </div>
22 );
23 }
24}
25
1class Car extends React.Component{
2 constructor(props){
3 super(props);
4 this.state = {
5 brand: "BMW",
6 color: "black"
7 }
8 }
9}
10