import React, { Component } from "react"; import { DiceRoller } from "../../services/dice-roller"; import { IRollFormState } from "./interfaces/i-roll-form-state"; class RollForm extends Component { private rollInputRef: React.RefObject; constructor(props: any) { super(props); this.state = { roll: 0 }; this.rollInputRef = React.createRef(); } private roll(e: any) { e.preventDefault(); const str = this.rollInputRef.current.value; const roll = DiceRoller.roll(str); this.rollInputRef.current.value = ""; this.setState({ roll }); } render() { return (
{this.state.roll}
); } } export { RollForm };