Problem Statement
What are functional components and class components in React?
Explanation
Functional components are simple JavaScript functions that return JSX. Class components are ES6 classes that extend React.Component and use a render() method. Functional components are now preferred because they are simpler and support Hooks.
Code Solution
SolutionRead Only
// Functional Component
function Welcome() {
return <h1>Hello!</h1>;
}
// Class Component
class Welcome extends React.Component {
render() {
return <h1>Hello!</h1>;
}
}