更改<button type="button"
为<button type="submit"
。删除onClick
。反而做<form className="commentForm" onSubmit={this.onFormSubmit}>
。这应该可以单击按钮并按回车键。
onFormSubmit = e => {
e.preventDefault();
const { name, email } = this.state;
// send to server with e.g. `window.fetch`
}
...
<form onSubmit={this.onFormSubmit}>
...
<button type="submit">Submit</button>
</form>