Name two types of React component
Name two types of React component
Name two types of React component
Two types of react Components are:
The two types are function components and class components.
1. Function component: a JavaScript function that returns JSX. With Hooks (useState, useEffect) it can have state and side effects. This is the recommended style today.
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
2. Class component: an ES6 class that extends React.Component and has a render() method. It uses this.state, this.setState() and lifecycle methods like componentDidMount.
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}Log in or create a free account to answer this question.