Having trouble using npm package oddslib

Viewed 51

I'm trying to use an npm package, oddslib, to convert betting odds from decimal to american odds. This form is giving me an error "invalid odds" from the npm package. Has anyone used this package, or can anyone help me figure out how to use this correctly?

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;
1 Answers

I think you want to be passing value instead of event in your handleSubmit function

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

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