Class Components

Pascual Vila
Frontend Instructor.
Class components are another way to define components in React. They are more complex than functional components, but before React 16.8, they were the only way to manage local state and use lifecycle methods.
Example of a Class Component:
{`import React, { Component } from "react";
class Counter extends Component {
constructor(props) {
super(props);
this.state = { count: 0 };
}
render() {
return (
<div>
<h1>Counter: {this.state.count}</h1>
<button onClick={() => this.setState({ count: this.state.count + 1 })}>Increment</button>
</div>
);
}
}
export default Counter;`}