React Components
React components are the building blocks of a React application. A component can be thought of as a self-contained module that encapsulates UI logic and behavior. React components can be defined as functional components or class components. Functional components are simpler and easier to read, while class components offer more advanced features such as lifecycle methods and state management.
Here's an example of a functional component:
function Greeting(props) {
return Hello, {props.name}!
;
}
And here's an example of a class component:
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = { count: 0 };
}
render() {
return (
Count: {this.state.count}
);
}
}