im trying to make a quizz project fetching api of quiz with answers and questions im so in the api there is array of wrong answers(3) and one correct answer i try to output them as buttons and i outtput the 3 wrong answers so i thought i would push the correct answer into the wrong answers array and then randomly sort them and output as answers but i get the errot that array of answers isnt iterable can anyone help me to solve this problem and tell me if im going in the right direction or not ?
import './App.css';
import axios from 'axios'
import {useState,useEffect} from 'react'
function App() {
const [quiz,setQuiz] = useState([])
const [answer,setAnswer] = useState([])
useEffect(()=>{
axios.get('https://opentdb.com/api.php?amount=10')
.then(res=>{
setQuiz(res.data.results[0])
setAnswer([...quiz.incorrect_answers, quiz.correct_answer])
})
.catch(err=>{
console.log(err);
})
},[])
return (
<div className="App">
<h1>{quiz.question}</h1>
{answer && answer?.map(answers =>
<button key={answers}>{answers}</button>)
}
</div>
);
}
export default App;