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

366
Views
Why is array.includes() always returning false in React Typescript with useReducer Hook?

Asked the question earlier today, thinking it was a problem that needed async to work, was advised that includes() doesn't need an async implementation and was recommended that I ask again. So, here we go,

I am using .includes() method to check if a word is valid, by checking for inclusion on a 12,000 element or so array. The method always returns false. I've tried to isolate the bug with no success. Perhaps someone can spot an obvious typo or bug I've just over looked? I will include the interfaces at the bottom in case those are helpful.

//helpers.ts
// I have checked to make sure the word is valid, including casing, it doesn't work, even if I pass it a string literal.
export function validateGuess(guess: GuessCharacter[]) {
  let word: string = '';

  for (let character of guess) {
    word += character.value;
  }
 
  return allWords.includes(word);
}

it is called in my reducer

//gameStateReducer.ts
...
case ActionKind.Enter: {
      if (guesses[guessCount][4].value === ' ') {
        console.log('Not enough letters');
        return gameState;
      }

      if (!validateGuess(guesses[guessCount])) {
        console.log('Not in word list');
        return gameState;
      }

      //continues process and returns updated state
      ...
    }

which is called by the event handler

//index.ts, modified, I actually pass a whole object but it's a little verbose for the post/issue
  function handleEnterPress() {
    dispatch(keyAction.Enter);
  }

which is the callback in this component

//Keyboard.tsx
<button className="enter-button" onClick={handleEnterPress}>
  ENTER
</button>
interface GuessCharacter {
  value: string;
  place: number; //zero-indexed
  correctValue: boolean;
  correctPlace: boolean;
  submitted: boolean;
}

interface GameState {
  solution: string;
  guesses: GuessCharacter[][];
  guessCount: number; //zero-indexed
  characterBank: KeyboardCharacter[];
}

Thanks, my apologies if there is an assumption that I left unstated, I have reread the post and hope my question is good to go.

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!