Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
Forked from arbales/comment_form.jsx
Last active December 17, 2015 23:08
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 subtleGradient/5686817 to your computer and use it in GitHub Desktop.
Save subtleGradient/5686817 to your computer and use it in GitHub Desktop.
<element name="comment-form" constructor="CommentForm">
<template>
<form class="commentForm" onSubmit={this.handleSubmit}>
<input type="text" placeholder="Your name" ref="author" />
<input
type="text"
placeholder="Say something..."
ref="text"
/>
</form>
</template>
<script>
CommentForm.prototype.handleSubmit = function(){
var author = this.refs.author.getDOMNode().value.trim();
var text = this.refs.text.getDOMNode().value.trim();
if (!text || !author) {
return;
}
// TODO: send request to the server
this.refs.author.getDOMNode().value = '';
this.refs.text.getDOMNode().value = '';
}
</script>
</element>
<element name="timer" constructor="Timer">
<template>
<div>Seconds Elapsed: {{this.state.secondsElapsed}}</div>
</template>
<script>
Timer = React.createClass({
getInitialState: function() {
return {secondsElapsed: 0};
},
tick: function() {
this.setState({secondsElapsed: this.state.secondsElapsed + 1});
},
componentDidMount: function() {
setInterval(this.tick.bind(this), 1000);
}
});
</script>
</element>
@subtleGradient
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment