Class components can hold and manage their own state and have a separate render method to return JSX on the browser. It is also called as stateful components as they can have a state. There are two ways to extends component one is a React.Component and another one is a Component.
Features in class components are
- It is a method that’s automatically called during the creation of an object from a class
- It is used for initializing the local state of the component by assigning an object to this. state.
- It is used for binding event handler methods that occur in your component.
super:
It is used to call the constructor of its parent class.
super vs super(props):
When you want to access this.props in the constructor
See the below example for increment button in using class components
0 Comments
Post a Comment