What is the main purpose of constructor?
The constructor is mainly used for two purposes,
- To initialize local state by assigning object to this.state
- For binding event handler methods to the instance For example, the below code covers both the above cases,
constructor(props) {super(props);// Don't call this.setState() here!this.state = { counter: 0 };this.handleClick = this.handleClick.bind(this);}
June 11, 2022
146
Read more
What is React?
November 06, 2022
ReactJSHow to programmatically trigger click event in React?
November 06, 2022
ReactJS