set.State

조다희·2021년 2월 5일
0

import React from "react";
import PropTypes from "prop-types"

class App extends React.Component {
state = {
count: 0
};
add = () => {
this.setState({ count: this.state.count + 1});
};
minus = () => {
this.setState({ count: this.state.count - 1});
};
render() {
return

  <h1>The number is: {this.state.count}</h1>;
  <button onClick={this.add}>Add</button>
  <button onClick={this.minus}>Minus</button>
  </div>

}

}

export default App;

stateSet을 호출할 때마다 새로운 state와 함께 render function을 호출한다.

profile
블로그 옮김 https://daheejo.tistory.com/

0개의 댓글