React TutorialLesson 22Free preview
React Class
This lesson is part of React · All levels
Summary
In addition to functions, the React component can be written as a class that extends React.Component. The class component stores internal data on the state object and accesses it via this.state, while the changes are made via this.setState. For modern projects functional components with hooks are preferred, but classes are still often found on older codes.
Key points
- Class component must extend React.Component and have a render method
- Internal data is stored in the state and read via this.state
- State changes are made, not direct assignments
- Lifecycle methods such as componentDidMount are used on class components
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.