I have a joinQuiz.js file where users can join a quiz. I want when the user hits the join button, the quiz title and quiz id data to be passed on the next page i.e quiz.js file via App.js file. I used react-router to navigate through the files
joinQuiz.js
<Table striped bordered hover>
<thead>
<tr>
<th>
Quiz
</th>
<th>
Join
</th>
</tr>
</thead>
<tbody>
{info.map((quiz) => (
<tr>
<th>
<h5>{quiz.title}</h5>
<p> Creator : {quiz.creator} {quiz.email}</p>
</th>
<th>
<Button type="submit" href="/quiz"> Join </Button> //(HERE I WANT TO PASS QUIZ DATA TO NEXT PAGE I.E QUIZ.JS)
</th>
</tr>
))}
</tbody>
</Table>
App.js file. here I have used react-router to navigate to the files. I don't know if I can directly pass the data from joinQuiz.js to quiz.js without doing any changes in app.js.
function App() {
return (
<div>
<Router>
<Header />
<Switch>
<Route path="/" exact component={Home} />
<Route path="/creategame" exact component={createGame} />
<Route path="/join" exact component={JoinQuiz} />
<Route path="/quiz" exact component={Quiz} />
</Switch>
<Footer/>
</Router>
</div>
);
}
quiz.js
Here I want to catch the quiz data when the user hits the join button.
const Quiz = ( props) => {
const [questions, setQuestions] = useState([]);
const [id, setId] = useState('jAApdF8FrX9GSMnDziCxm');
const [type, setType] = useState('mcq');
const[name, setName] = useState('');
const[email,setEmail] = useState('');
const [step, setStep] = useState(0);
const[score, setScore] = useState(0)
var result = 0
var response = []
const array = []
useEffect(() => {
axios.post("http://localhost:3500/app/initialdata", { id: id })
.then((response) => {
setQuestions(response.data.message)
})
}, [])
return (
<Container style={{paddingTop:"80px"}}>
<h3 style={{paddingTop: "20px", marginLeft:"20px"}}>Quiz " **Here I want to print qui title *** </h3>
<p style={{marginLeft:"20px"}}>Type : **Here I want to print Quiz Type *** </p>
<p style={{marginLeft:"20px"}}>Creator : </p>
</Container>
)
}
