ReactQuestion 08 of 28
Difference between class components and functional components?
Answer out loud or in your head first, then compare.
Answer
Class:
JSX
class Counter extends React.Component {
state = {
count: 0
};
render() {
return <div>{this.state.count}</div>;
}
}Functional:
JSX
function Counter() {
const [count, setCount] =
useState(0);
return <div>{count}</div>;
}Today the standard is function components + hooks.
You can still meet class components in older code.
How did it go? Be honest — “Not yet” puts the question on your review list.