React JS - State with class component
App.js -
import './App.css';
import React, {useState, Component} from 'react';
class App extends Component{
constructor(){
super();
this.state={data:"Krishan"}
}
fun2(){
this.setState({data:"Dev"})
}
render(){
return(
<div>
<h1>{this.state.data}</h1>
<button onClick={()=>this.fun2()}>Click Me</button>
</div>
)
}
}
export default App;
Comments
Post a Comment