React Native If Statement Not Functioning properly with State

  javascript, node.js, reactjs

I have created this function in react native:

confirmOTP(){
  console.log(this.state.otpEntry)
  console.log(this.state.sixDigitauth)
  if (this.state.otpEntry === this.state.sixDigitauth){
    this.setState({
      modalVisibility: false
    })
    console.log ("authenticated")
  }else{
    console.log ("incorrect OTP")
  }
}

Although the function console logs both this.state.otpEntry and this.state.sixDigitauth and the text in them matches, I still end up getting a console log of "incorrect OTP". This means that the if statement is unable to match both states.
464042 464042 incorrect OTP

Both data types are text:
this.state = { sixDigitauth: '', otpEntry: '', }

Any idea why?

thanks in advance

Source: Ask Javascript Questions

LEAVE A COMMENT