Skip to content

Instantly share code, notes, and snippets.

@makenai
Last active August 29, 2015 14:27
Show Gist options
  • Save makenai/820b21292e8a2b9c73e8 to your computer and use it in GitHub Desktop.
Save makenai/820b21292e8a2b9c73e8 to your computer and use it in GitHub Desktop.
var Poll = React.createClass({
getInitialState: function() {
return {
question: {
title: ''
}
}
},
componentDidMount: function(data) {
$.get('/yourDataURL/' + this.props.id, function(data) {
if ( this.isMounted() ) {
this.setState(data);
};
}.bind(this))
},
render: function() {
return (
<div>
<h1>{this.state.question.title}</h1>
</div>
);
}
});
var Poll = React.createClass({
getInitialState: function() {
return {
question: {
title: ''
},
avatar: '/img/default.png',
options: {
showingAvatar: true
}
}
},
componentDidMount: function(data) {
$.get('/yourDataURL/' + this.props.id, function(data) {
if ( this.isMounted() ) {
this.setState(data);
};
}.bind(this))
},
render: function() {
return (
<div>
<PollHeader title={this.state.question.title} avatar={this.state.options.showingAvatar && this.state.avatar}/>
</div>
);
}
});
var PollHeader = React.createClass({
render: function() {
var avatar = '';
if (this.props.avatar) {
avatar = '<img src="' + this.props.avatar + '" />';
}
return (
<div>
{avatar}
<h1>{this.props.title}</h1>
</div>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment