Created
February 17, 2016 03:01
-
-
Save syntacticsugar/90bd84524f29bc858e9a to your computer and use it in GitHub Desktop.
yet another review of <TweetBox />
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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