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

113
Views
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 answers
Answer question

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