Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda