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

191
Vistas
Why am I getting an error in resetting state? React

I am currently building a quiz-type game with React.

However, I am getting an error seemingly at random sometimes.

The error that it shows me is:

const state=useContext(QuestionsStateContext)
  11 |   let question=state.question[0]
> 12 |   let photoSrc=question.questionPhoto.value;
return (
  14 |         <>
  15 |         <div className='cardquestion'>

I don't think the problem is here. I think it might be an issue with state, that it's not resetting the questions after it's finished. I was wondering how I can reset the state of the deck of questions after completion, so that it can restart the test. I don't know for sure yet if this is the problem either, so any help appreciated, thanks.

Also, this is the part of the quiz game that handles the logic. I still am not sure where the problem is and have been struggling to figure it out for a while now.

    import { nanoid } from "nanoid";

    export const shuffler = (a) => {

    for (let i = a.length - 1; i > 0; i--) {

      const j = Math.floor(Math.random() * (i + 1));

       [a[i], a[j]] = [a[j], a[i]];

         }

         return a;

    };


      // takes 10 random cards from shuffled deck of each type
      const deckMaker=(arr)=>{
      const newDeck=shuffler(arr)
      const tenCards=newDeck.slice(0,10)
      return tenCards
    }

    // shuffle each type first... then combine
    // and then shuffle twice. 
    const deckOne=deckMaker(oneType)
    const deckTwo=deckMaker(twoType)
    const deckThree=deckMaker(threeType)
    const deck=deckOne.concat(deckTwo)
    const finalDeck=deck.concat(deckThree)
    const shuffledFinal=shuffler(finalDeck);

    export const deckShuffled=shuffler(shuffledFinal)

Thank you!

about 4 years ago · Juan Pablo Isaza
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