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

189
Views
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
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!