Skip to content

Instantly share code, notes, and snippets.

@syntacticsugar
Created February 17, 2016 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syntacticsugar/90bd84524f29bc858e9a to your computer and use it in GitHub Desktop.
Save syntacticsugar/90bd84524f29bc858e9a to your computer and use it in GitHub Desktop.
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