-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuiz.js
33 lines (28 loc) · 872 Bytes
/
Quiz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from "react";
import { useSelector } from "react-redux";
import { Link, useParams, Navigate } from "react-router-dom";
import Card from "../cards/Card";
import ROUTES from "../../app/routes";
// import quiz selector
import { selectQuizzes } from "./quizzesSlice";
export default function Quiz() {
const quizzes = useSelector(selectQuizzes); // call to your selector to get all the quizzes in state
const { quizId } = useParams();
const quiz = quizzes[quizId];
if (!quiz) {
return <Navigate to={ROUTES.quizzesRoute()} replace />
}
return (
<section>
<h1>{quiz.name}</h1>
<ul className="cards-list">
{quiz.cardIds.map((id) => (
<Card key={id} id={id} />
))}
</ul>
<Link to={ROUTES.newQuizRoute()} className="button center">
Create a New Quiz
</Link>
</section>
);
}