import React from 'react'; class CommentForm extends React.Component { getInitialState() { return { author: '', text: '' }; } handleAuthorChange(e) { this.setState({ author: e.target.value }); } handleTextChange(e) { this.setState({ text: e.target.value }); } handleSubmit(e) { e.preventDefault(); const author = this.state.author.trim(); const text = this.state.text.trim(); if (!text || !author) { return; } this.props.onCommentSubmit({ author, text }); this.setState({ author: '', text: '' }); } render() { return (
); } } CommentForm.propTypes = { author: React.PropTypes.string, text: React.PropTypes.string, onCommentSubmit: React.PropTypes.func, };