import React, { Component } from 'react'; import './App.css'; class App extends Component { constructor(...stuff) { super(...stuff) this.state = { wc: 0, goal: "", } } render() { const pct = ((this.state.wc / (this.state.goal || 250)) * 100) return (
{this.state.wc}  /  { pct.toFixed(pct < 10 ? 1 : 0) }%
); } onRef(ta) { this.ta = ta } onRef2(tb) { this.tb = tb } onChange() { clearTimeout(this.timeout) this.timeout = setTimeout(() => { const wc = this.ta.value.split("\n").join(" ").split(" ").filter(t => t.length > 0).length this.setState({wc}) }, 100) } onChange2() { let goal = parseInt(this.tb.value) if (goal > 0) { this.setState({goal}) } else { this.setState({goal: ""}) } } } export default App;