본문 바로가기
React

this.toggle 여러개 작동하게 코딩하기

by 바나냥 2020. 4. 10.
class ModalExample extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      modal: true,
      tooltipOpen: false
    };

    this.toggleModal = this.toggleModal.bind(this);
    this.toggleTooltip = this.toggleTooltip.bind(this);
  }

  toggleModal() {
    this.setState({
      modal: !this.state.modal
    });
  }
  toggleTooltip() {
    this.setState({
      tooltipOpen: !this.state.tooltipOpen
    });
  }

...
}

<span className="closeBt" onClick={this.toggleModal}></span>
<Tooltip isOpen={this.state.tooltipOpen}></Tooltop>
​

댓글