I was working with react.js and I added this.setState() in the constructor but it doesnt work.
Here is my code -
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
age: '18'
}
this.setState({id: 'name'});
}
render(){
return (
<div>
<p>{this.state.id}</p>
<p>{this.state.value}</p>
</div>
)
}
}
This renders the second p tag but not the first why so?