2

我正在尝试使用 npm 包,oddslib,将投注赔率从十进制转换为美国赔率。此表单从 npm 包中给我一个错误“无效赔率”。有没有人使用过这个包,或者任何人都可以帮我弄清楚如何正确使用这个包?

https://www.npmjs.com/package/oddslib/v/1.0.3

import oddslib from "oddslib";

class BettingCalculator extends React.Component {
  state = { value: "" };

  handleChange = (e) => {
    console.log(e.target.value);
    this.setState({
      value: e.target.value,
    });
  };

  handleSubmit = (e) => {
    e.preventDefault();
    var odds = oddslib.from("decimal", e).to("moneyline");

    console.log(odds);
    return odds;
  };

  render() {
    return (
      <div>
        <h1>Betting Calculator</h1>
        <form onSubmit={this.handleSubmit}>
          <input
            type="number"
            value={this.state.value}
            placeholder="Decimal"
            onChange={this.handleChange}
          />
          <input type="submit" value="Submit" />
        </form>
      </div>
    );
  }
}

export default BettingCalculator;
4

1 回答 1

1

我认为您想在 handleSubmit 函数中传递值而不是事件

 handleSubmit = (e) => {
    e.preventDefault();
    var odds = oddslib.from("decimal", this.state.value).to("moneyline");

    console.log(odds);
    return odds;
  };
于 2020-07-07T05:44:50.287 回答