export default class setState extends React.Component{
constructor(){
super();
this.state = {
data:[],`enter code here`
'header':'this is header'
}
}
updateState(){
var arr = this.state.data;
var temp = 'setState... ';
arr.push(temp);
this.setState({data:arr});
}
render(){
return(
<div>
<h1>Set State</h1>
<button onClick={this.updateState.bind(this)} >Update State </button>
<p>{this.state.data}</p>
<h3>{this.state.header}</h3>
<h2>Random value : {Math.random()}</h2>
</div>
)
}
}
I don't want to update h2 tag the "Random Value". When i click on the "Update button" i am pushing value in the array and doing "setState". But it also update my h2 tag.