Skip to content

Commit efe1161

Browse files
committed
Next Question
1 parent 32b3a72 commit efe1161

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/App.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import SetupForm from "./SetupForm";
55
import Loading from "./Loading";
66
import Modal from "./Modal";
77
function App() {
8-
const { waiting, loading, questions, index, correct } = useGlobalContext();
8+
const { waiting, loading, questions, index, correct, nextQuestion } =
9+
useGlobalContext();
910

1011
if (waiting) {
1112
return <SetupForm></SetupForm>;
@@ -39,7 +40,9 @@ function App() {
3940
})}
4041
</div>
4142
</article>
42-
<button className="next-question">next question</button>
43+
<button className="next-question" onClick={nextQuestion}>
44+
next question
45+
</button>
4346
</section>
4447
</main>
4548
);

src/context.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ const AppProvider = ({ children }) => {
4747
}
4848
};
4949

50+
const nextQuestion = () => {
51+
setIndex((oldIndex) => {
52+
const index = oldIndex + 1;
53+
if (index > questions.length - 1) {
54+
//open Model
55+
return 0;
56+
} else {
57+
return index;
58+
}
59+
});
60+
};
61+
5062
useEffect(() => {
5163
fetchQuestions(tempUrl);
5264
}, []);
@@ -61,6 +73,7 @@ const AppProvider = ({ children }) => {
6173
correct,
6274
error,
6375
isModalOpen,
76+
nextQuestion,
6477
}}
6578
>
6679
{children}

0 commit comments

Comments
 (0)