I am just messing around in React as a beginner. I am trying to make a questionnaire. I ask the user whether they have a laptop, and then continue asking questions about it. If the 'yes' button is clicked on the first question, the next question is displayed - what kind of laptop. Here I want to display 3 options in the form of buttons instead of 2 like the previous question and the chain continues. If 'no' is clicked on the first question, another question is displayed. I want these questions to be on the same webpage and not redirected to another page. I also want the upcoming question buttons to not be displayed initially itself. I have a good understanding of HTML and JS and basic level fundamentals of React.
class App extends React.Component {
constructor() {
super();
this.state = { showMessage: false }
}
_showMessage = (bool) => {
this.setState({
showMessage: bool
});
}
render() {
return (
<div>
Do you have a laptop <br/>
<button onClick={this._showMessage.bind(null, true)}>yes</button>
<button onClick={this._showMessage.bind(null, false)}>no</button>
{ this.state.showMessage && (<div>What kind of laptop?</div>) }
<br/>
{/* I want to hide these buttons until the 'yes' button is clicked*/}
<button onClick={this._showMessage.bind(null, true)}>Windows</button>
<button onClick={this._showMessage.bind(null, false)}>IOS</button>
{/* I want to display a third button which says none of the above */}
{ this.state.showMessage && (<div>when did you buy it?</div>) }
</div> )
}
}
if step === x then return y