Я новичок в React и пытаюсь создать простое веб-приложение для квадратичного калькулятора. Для каждой переменной есть три входа: a, b и c. Независимо от того, какие числа я ввел в возвращаемые значения, они всегда равны NaN. Помощь будет высоко ценится. Код:
import React, { Component } from 'react';
import './App.css';
class App extends Component {
constructor() {
super();
this.state = {
a: null,
b: null,
c: null
};
this.publish = this.publish.bind(this);
this.handleChange = this.handleChange.bind(this);
}
handleChange({ target }) {
this.setState({
[target.name]: target.value
});
}
publish(a, b, c) {
document.write((-1 * b + Math.sqrt(Math.pow(b, 2) - (4 * a * c))) /
(2 * a) + "<br/>" +
(-1 * b - Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a));
}
render() {
return(
<div>
<input
type="number"
name="Var A"
placeholder="Enter Variable A"
value={ this.state.a }
onChange={ this.handleChange }/>
<input
type="number"
name="Var B"
placeholder="Enter Variable B"
value={ this.state.b }
onChange={ this.handleChange }/>
<input
type="number"
name="Var C"
placeholder="Enter Variable C"
value={ this.state.c }
onChange={ this.handleChange }/>
<button value="Send" onClick={ this.publish }>Publish</button>
</div>
}
}
export default App;