I am trying to loop through multiple components in React. Essentially I would like the questions to loop through and transition similarly to the example for Lapsed User on https://iteratehq.com/.
Here is the main page that the components will loop in:
import React from 'react';
import Q1Name from './questions/Q1Name';
import Q2Birthday from './questions/Q2Birthday';
import Q3City from './questions/Q3City';
import Q4YouReady from './questions/Q4YouReady';
import Q5Setting from './questions/Q5Setting';
import Q6Length from './questions/Q6Length';
import Q7Email from './questions/Q7Email';
class SignUpPage extends React.Component {
render() {
const questions = [Q1Name, Q2Birthday, Q3City, Q4YouReady, Q5Setting, Q6Length, Q7Email];
const QList = questions.map(function(question){
return {question};
});
return (
<div className = "container-fluid">
<div className = "question-box">
<Q1Name />
</div>
</div>
);
}
}
export default SignUpPage;
The below is an example component I would like to bring in - note each question is slightly different. They take in name, email (with validation), city, birthday (date form), and various button answer options.
import React from 'react';
class Q1Name extends React.Component {
render() {
return (
<div className="questions">
<h1 id="question-h1">What is your name?</h1>
<form>
<div className="form-group">
<input type="name" className="form-control text-form custom-form" id="yourNameHere" aria-describedby="name" placeholder="" />
</div>
<button type="submit" className="btn btn-custom btn-lg" onClick={console.log("hallo")}>Next Question!</button>
</form>
</div>
);
}
}
export default Q1Name;
I have been able to get everything else working except for this part. Any help would be greatly appreciated!!