Beginner React Interview QuestionsBeginnerComparison
React · Question 4
What is the difference between function components and class components in React?
Direct answer
Function components are ordinary functions that return JSX and use Hooks for React features; class components use React.Component and lifecycle methods and are mainly encountered in older code.
| Feature | Function component | Class component |
|---|---|---|
| Definition | JavaScript function | Class extending React.Component |
| State and React features | Hooks such as useState and useEffect | this.state and lifecycle methods |
| this binding | Not required | Often relevant |
| New React code | Standard approach | Supported, but mostly legacy/maintenance |
Modern React documentation teaches function components first. Hooks are designed for function components and cannot be called inside class components.