如何在点击按钮时切换外壳

时间:2019-07-19 13:54:22

标签: reactjs typescript

我正在使用带有道具的开关盒进行反应,单击按钮时,我需要开关盒并显示数据。

我已经编写了代码,但是不知道如何在单击按钮时切换大小写

enum Statuses {
  SUCCESS = 'success',
  ERROR = 'error',
}

interface Props {
  confirmationStatus?: Statuses;
  error?: string;
}

public render() {
    return (
{this.getMessage()}
)
<button onClick={this.handleSubmit}> Submit </button>
}


private getMessage = () => {
    switch (this.props.confirmationStatus) {
      case Statuses.ERROR:
        return (
          <FormattedMessage {...messages.paymentError} />: reason

        );
      case Statuses.SUCCESS:
        return (         
            <FormattedMessage {...messages.paymentSuccess} />

        );
    }
  };

private handleSubmit = () => {
    const url = 'xxx';

    fetch(url, {
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      mode: 'cors',
      method: 'PATCH',
      body: JSON.stringify({
        orderCode: this.state.orderId
      }),
    })
      .then(response => response.text())
      .then(res => {
        this.state.resData = res;
      })
      .catch(e => console.log(e));

    console.log(this.state.resData);
  };
}

我应该在哪里编写代码以使用道具切换案例

0 个答案:

没有答案