Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
Reactjs: Why is my Android Virtual Device showing 'this.setState_if_Tie' is not a function?

I'm trying to make a tic-tac-toe game feature in my mobile application using react-native. But when the user won the game, the game didn't stop the round, instead, the game continues until every slot is filled and an error popped out saying that 'this.setState_if_Tie is not a function'.

On the other hand, when the result is a tie, the screen will freeze in white.

Below are some codes that are related to the said problem:

    judgeWinner(inputs){    //check the winning situation based on 'const conditions'
        return conditions.some(d => d.every(item => inputs.indexOf(item) !== -1));
    }

    //if result === -1  game continue , result === 0 user won
    //if result === 1  bot won , result === 2 no winner

    setstate_if_Win(parse_res, parse_result){
        if (parse_res && parse_result !== 0){
            this.setState({ result: 0});   //User win
        }
        if (parse_res && parse_result !== 1) {
            this.setState({ result: 1});  //Bot win
        }
    }

    setstate_if_Tie = () => {
        this.setState({ result: 2 });
    }

    componentDidUpdate() {
        const { userInputs , botInputs , result} = this.state;
        const inputs = userInputs.concat(botInputs);

        //res is result
        if (inputs.length >= 5) {
            let res = this.judgeWinner(userInputs);  // go to line 95 to check winning result for user
            if (res && result !== 0) {
                this.setstate_if_Win(res, result);   //User win
                return;
            }
            res = this.judgeWinner(botInputs);  // go to line 95 to check winning result for bot
            if (res && result !== 1) {
                this.setstate_if_Win(res, result);  //Bot win
                return;
            }
        }
        if (inputs.length >= 9 && result !== 2) {
            this.setState_if_Tie();    //No winner (Tie)
        }
    }

Is there any way that I can do to solve this problem? Thank you in advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You must named setState_if_Tie instead of setstate_if_Tie:

setstate_if_Tie = () => {
    this.setState({ result: 2 });
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda