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..89b61a8 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,10 +1,11 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import ResultCard from "./components/ResultCard"; import QuestionCard from "./components/QuestionCard"; import { shuffleArray } from "./lib/utils"; import rawTriviaQuestion from "./lib/data"; const triviaQuestion = rawTriviaQuestion.results[0]; +const TRIVIA_API = 'https://opentdb.com/api.php?amount=1&category=9&type=multiple' function App() { const [selectedAnswer, setSelectedAnswer] = useState(null); @@ -15,33 +16,39 @@ function App() { }; let card; - if (selectedAnswer) { - card = ( - - ); - } else { - let options = [ - questionData.correct_answer, - ...questionData.incorrect_answers, - ]; - card = ( - - ); - } + card = ( + + ); + } else { + let options = [ + questionData.correct_answer, + ...questionData.incorrect_answers, + ]; + card = ( + + ); + } + const getNewTrivia = async () => { + const fetchQuestion = fetch(TRIVIA_API) + fetchQuestion + .then((response) => response.json()) + .then((data) => {setQuestionData(data.results[0]); setSelectedAnswer(null); console.log(data.results[0])}) + .catch((error) => console.error('Error:', error)) + } return (

Trivia App

- + {card}