React | Class Components and Lifecycle Methods | Question 3

Last Updated :
Discuss
Comments

What will happen in this class component?

class Demo extends React.Component {

constructor(props) {

super(props);

this.state = { count: 0 };

this.setState({ count: 1 });

}

render() {

return <div>{this.state.count}</div>;

}

}


The component renders 1

The component renders 0

Infinite re-render loop

Error: Cannot call setState in constructor

Share your thoughts in the comments