I'm learning ReactJS. I'm looking the tutorial - http://facebook.github.io/react/docs/tutorial.html
On submit the script read JSON from the server:
handleCommentSubmit: function(comment) {
var comments = this.state.data;
comments.push(comment);
this.setState({data: comments}, function() {
// `setState` accepts a callback. To avoid (improbable) race condition,
// `we'll send the ajax request right after we optimistically set the new
// `state.
$.ajax({
url: this.props.url,
dataType: 'json',
type: 'POST',
data: comment,
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
});
},
And update data. How can I send error message from JSON? Something like this:
<Comment author={comment.author} key={index}>
{comment.text}
<div class="error">Error</div>
</Comment>
Should I set it in data:
this.setState({[{name: 'John', text: 'text', error: 'error'}]});
And change comments?:
<Comment author={comment.author} key={index}>
{comment.text}
<div class="error">{comment.error}</div>
</Comment>