Skip to content

Instantly share code, notes, and snippets.

@sethmcl
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save sethmcl/eb6153744601a01078c4 to your computer and use it in GitHub Desktop.

Select an option

Save sethmcl/eb6153744601a01078c4 to your computer and use it in GitHub Desktop.
const Question = React.createClass({
handleGetStarted: function(event) {
this.nextQuestion(event);
},
qdata: [
{
id: 0,
type: "m-choice",
question: "Are you ready to get started?",
options: [
{
value: "Oh yeah!",
handler: "handleGetStarted"
}
]
},
render: function () {
var currQuestion = qdata[this.state.questionId]
if (currQuestion.type === "m-choice") {
var answers = <MChoiceAnswers options={currQuestion.options} question={this} /> ;
} else if (currQuestion.type === "text") {
var answers = <TextAnswers question={currQuestion} /> ;
}
return (
<div className="question">
<p> {currQuestion.question } </p>
{answers}
</div>
);
}
});
const MChoiceAnswers = React.createClass({
render: function() {
var createItem = function(answer) {
return (
<Button onClick={ this.props.question[answer.handler].bind(this.props.question) }> { answer.value } </Button>
);
};
return (
<div>
{this.props.options.map(createItem) }
</div>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment