class App extends React.Component {
state = {
age: 29,
}
constructor(props) {
super(props);
console.log('constructor', props);
}
render() {
console.log('render');
return (
<div>
<h2>
Hello {this.props.name} - {this.state.age}
</h2>
</div>
);
}
componentWillMount() {
console.log("componentWillMount");
}
componentDidMount() {
console.log("componentDidMount");
// state 를 update 시켜주니까 render 가 다시 호출 되고 있다.
setInterval(() => {
console.log('setIn')
this.setState(state => ({
...state,
age : state.age + 1
}))
}, 1000);
}
}