reactState
import React, { Component } from 'react'
export class counter extends Component {
constructor(props) {
super(props)
this.state = {
count:0
}
}
increment=()=>{
this.setState(
prevState=>
({
count:prevState.count+1
}),()=>{
console.log(this.state.count);
})
//console.log(this.state.count);
}
// incrementTwo=()=>{
// this.increment();
// this.increment();
// }
render() {
return (
<div>{this.state.count}
<button onClick={()=>this.increment()}>click</button>
</div>
)
}
}
export default counter
Comments
Post a Comment