REACT
노마드 코더 state 와 componentDidMount와 componentDidUpdate 예제
Made Project
2020. 7. 1. 15:36
import React from 'react';
class App extends React.Component{
constructor(props){
super(props)
console.log("hello")
}
state = {
count: 0
};
add = () => {
this.setState(current => ({ count:current.count +1 }));
}
minus = () => {
this.setState(current => ({ count:current.count -1 }));
};
componentDidMount(){
console.log("component rendered");
}
componentDidUpdate(){
console.log("i just updated");
}
render(){
console.log("im rendering");
return(
<div>
<h1>The number is:{this.state.count}</h1>
<button onClick={this.add}>Add</button>
<button onClick={this.minus}>Minus</button>
</div>
)
}
}
export default App;