diff --git a/package-lock.json b/package-lock.json index 254efeb..bd79634 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "lab-react-trivia-solution", - "version": "0.0.0", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "lab-react-trivia-solution", - "version": "0.0.0", + "version": "0.2.0", "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" diff --git a/src/App.jsx b/src/App.jsx index b7bde75..cba35b2 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -14,6 +14,22 @@ function App() { setSelectedAnswer(selection); }; + // It is having that rate limit issue, where if you click next question too fast + // it wont go to the next question but rather reload this question. + + const fetchQuestion = async () => { + const response = await fetch( + "https://opentdb.com/api.php?amount=1&category=9&type=multiple" + ); + const data = await response.json(); + setQuestionData(data.results[0]); + }; + + const handleNextQuestion = () => { + setSelectedAnswer(null); + fetchQuestion(); + }; + let card; if (selectedAnswer) { @@ -41,7 +57,9 @@ function App() {

Trivia App

- + {card}