-
Notifications
You must be signed in to change notification settings - Fork 0
/
classcom.js
38 lines (37 loc) · 1.22 KB
/
classcom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from 'react';
import ReactDOM from 'react-dom';
export class Counter extends React.Component{
constructor(props){
super(props);
this.state={count:1,massage:"reza noori"}
}
myfunction(e){
console.log([e.clientX,e.clientY])
}
componentDidMount(){
console.log("didmount")
document.addEventListener("click",this.myfunction)
}
componentDidUpdate(){
console.log("did update",this.state)
}
componentWillUnmount(){
console.log("un mount")
document.removeEventListener("click",this.myfunction)
}
render(){
return(<><h1>{this.state.count}</h1>
<button onClick={()=>{
this.setState({...this.state,count:this.state.count+1})
}}>+</button>
<button onClick={()=>{
this.setState({...this.state,count:this.state.count-1})
}}>-</button>
<button onClick={()=>{
this.setState({...this.state,count:0})
}}>reset</button>
<button onClick={()=>{
ReactDOM.render(<h1>salam</h1>,document.getElementById("root"))
}}>unmount</button></>)
}
}