Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
How to to put fetched data into the state?

I am trying to put fetched data into the state but it's not working, please let me know what I am doing wrong here, and also I want specific data to be inside the state like in this example I want only questions, answers, and incorrect answer, also I wanted to put the whole data into the array of object

const [quiz,setQuiz]=useState({});

useEffect(()=>{
  const  getQuizData =async ()=>{
  const res = await fetch("https://opentdb.com/api.php?amount=10")
  const data = await res.json();
  setQuiz({data});
  }
  getQuizData();


},[])
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

what coming from your data is below. I suspect what you want is setQuiz(data.results) also initializing like useState([]) should help too.

const data = {
  response_code: 0,
  results: [
    {
      category: 'History',
      type: 'multiple',
      difficulty: 'medium',
      question: 'Joseph Smith was the founder of what religion?',
      correct_answer: 'Mormonism',
      incorrect_answers: ['Buddhism', 'Christianity', 'Hinduism'],
    },
    {
      category: 'Sports',
      type: 'multiple',
      difficulty: 'medium',
      question: 'In a game of snooker, what colour ball is worth 3 points?',
      correct_answer: 'Green',
      incorrect_answers: ['Yellow', 'Brown', 'Blue'],
    },
  ],
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!