Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
yet another review of <TweetBox />
var TweetBox = React.createClass({
getInitialState: function() {
return {
text: "",
photoAdded : false,
};
},
togglePhoto : function(event) {
this.setState({ photoAdded: !this.state.photoAdded })
},
remainingChars : function() {
if (this.state.photoAdded) {
return 140 - 21 - this.state.text.length;
} else {
return 140 - this.state.text.length;
}
},
handleChange: function(event) {
this.setState({ text: event.target.value });
},
render : function() {
return (
<div className="well clearfix">
<textarea onChange={this.handleChange} className="form-control"></textarea>
<br/>
<button disabled={this.state.text.length === 0 && !this.state.photoAdded} className="btn btn-primary pull-right">Tweet</button>
<button onClick={this.togglePhoto} className="btn btn-primary pull-right">{this.state.photoAdded ? "✓ photo added" : "add photo"}</button>
<p>{this.remainingChars()}</p>
</div>
);
}
});
ReactDOM.render(
<TweetBox />,
document.getElementById("container")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment