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

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

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 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