Hi,
I’ve been running into a small issue, and I have no idea what’s going wrong and why… This may be my fault for not using it right, but please correct me!
I have my Main layout:
Main = React.createClass({
render() {
return <body>
<div className="body-wrapper">
<PersonalMenu />
<div className="content-wrapper">
<Header />
{this.props.content}
<GameForm />
<Footer />
</div>
</div>
</body>
}
});
My GameForm is this
GameForm = React.createClass({
handleSubmit: function(e) {
e.preventDefault();
var author = this.refs.author.value.trim();
var text = this.refs.text.value.trim();
if (!text || !author) {
return;
}
console.log(author);
console.log(text);
// TODO: send request to the server
this.refs.author.value = '';
this.refs.text.value = '';
return;
},
render: function() {
return (
<form className="commentForm" onSubmit={this.handleSubmit}>
<input type="text" placeholder="Your name" ref="author" />
<input type="text" placeholder="Say something..." ref="text" />
<input type="submit" value="Post" />
</form>
);
}
});
However, when I visit the page, the onSubmit is NOT working at all. The form just gets posted and the page refreshes.
When I change my Main to
Main = React.createClass({
componentDidMount: function() {
ReactDOM.render(<GameForm />, document.getElementById("render-target"));
},
render() {
return <body>
<div className="body-wrapper">
<PersonalMenu />
<div className="content-wrapper">
<Header />
{this.props.content}
<div id="render-target"> </div>
<Footer />
</div>
</div>
</body>
}
});
The onsubmit works when using the last Main layout. What’s going wrong? Am I doing something wrong? Or what is supposed to happen?