title: ReferenceError: Can't find variable: state in React Native 0.60.4
body: <p>I am using React native 0.60.4 with react-native-router-flux 4.0.6.
  I have a login component which works fine but when I redirect the user to login screen after the user has changed the password, the above error pops up and the app crashes.</p>
  <p>I tried printing the state variable in <code>ComponentDidMount()</code> - it gets printed. All the logs in the constructor where I am initializing the state variable are printed.
  Post this the error pops up and the app crashes.</p>
  <p>Part of error message:</p>
  <blockquote>
  <p>[08:42:09] I | ReactNativeJS ▶︎ login componentDidMount</p>
  <p>[08:42:09] E | ReactNativeJS ▶︎ ReferenceError: Can't find variable: state</p>
  </blockquote>
  <p>I believe there is no issue in the code since its working fine whenever the app is loaded.</p>
  <p>CODE:</p>
  <pre><code>    import * as React from 'react';
      // import React, { Component } from &quot;react&quot;;
      import {
          StyleSheet,
          Text,
          TouchableOpacity, 
          ToastAndroid,
          AppState,
          Dimensions,
          View,
          ImageBackground,
          Image,
          DeviceEventEmitter,
          LayoutAnimation,
          UIManager,
          Platform,
          Keyboard
          // AsyncStorage
          // NetInfo
      } from &quot;react-native&quot;;
      
      import AsyncStorage from '@react-native-community/async-storage';
      import NetInfo  from '@react-native-community/netinfo';
      
      import { Actions } from 'react-native-router-flux'; 
      import { Bars } from 'react-native-loader';
      import Nointernet from './NoInternet';
      import axios from 'axios';
      import TextField from './lib/TextField';
      import { PermissionsAndroid } from 'react-native';
      import firebase from 'react-native-firebase';
      
      let deviceWidth = Dimensions.get('window').width;
      let elementWidth = 0.8*deviceWidth;
      let screenHeigth = Dimensions.get('window').height;
      
      const unsubscribe=NetInfo.addEventListener((change)=&gt;{ this.handleConnectivityChange });
      
      class LoginScreen extends React.Component {
          constructor(props) {
              console.log(&quot;Props done&quot;);
              super(props);
              console.log(&quot;State issue&quot;);
              this.state = { 
                  appState: AppState.currentState,  
                  hidePwd:true,
                  pntoken: '', 
                  username: '', 
                  passwd: '', 
                  text: '', 
                  checkinternet:false,
                  nointernet:false,
                  isLoading: false ,
                  visibleHeight: Dimensions.get('window').height ,
  
              logo_height:100,
              logo_width:100,
              pwd_backup:''
              
          };
          console.log(&quot;State initialized&quot;);
          this.handleConnectivityChange = this.handleConnectivityChange.bind(this);
          this._handleAppStateChange = this._handleAppStateChange.bind(this);
          this.requestLocationPermission = this.requestLocationPermission.bind(this);
          
          if (Platform.OS === 'android') {
            UIManager.setLayoutAnimationEnabledExperimental(true);
          }
      }
  
      async getfcmtooken(){
          let pn_token = await firebase.messaging().getToken();
          if(pn_token){
              console.log(&quot;PNTOKEN&quot;)
              // if(this.state!=undefined)
              //     this.setState({ pntoken: pn_token});
              console.log(&quot;have TOKN&quot;);
              // if(this.state!=undefined)
              //     console.log(this.state.pntoken);
              this.updateToken(pn_token);
          }
          else{
              console.log(&quot;Loggged in. PN_TOKEN&quot;)
              this.tokenRefreshListener = firebase.messaging().onTokenRefresh((pn_token) =&gt; {
                  console.log('response getfcmtooken');
                  if (pn_token) {
                      console.log(&quot;got token&quot;)
                      // if(this.state!=undefined)
                      //     this.setState({ pntoken: pn_token})
                      this.updateToken(pn_token);
                      // if(this.state!=undefined)
                      //     console.log(this.state.pntoken);
                  }
              });
              console.log('getfcmtooken')
          }   
      }
  
      updateToken(token) {
          console.log('App updateToken');
          AsyncStorage.getItem('org_id').then((orgId) =&gt; {
              if(orgId != null){
                  console.log('orgId');
                  console.log(orgId);
                  let org_id = JSON.parse(orgId);
                  console.log('org_id');
                  console.log(org_id);
                  AsyncStorage.getItem('email').then((useremail) =&gt; {
                      let email = JSON.parse(useremail);
                      if(email){
                          console.log('email');
                          AsyncStorage.getItem('token').then((tokenvalue) =&gt; {
                              if(tokenvalue!=null){
                                  console.log('user_id');
                                  console.log(tokenvalue);
                                  let tokenV = JSON.parse(tokenvalue);
                                  console.log(&quot;PN TOKEN&quot;);
                                  console.log(token);
  
                                  axios({
                                      method: 'PUT',
                                      url: this.props.apiurl+'/pushnotification/updatetoken', 
                                      data: JSON.stringify({
                                          email: email,
                                          pntoken: token,
                                      }), 
                                      timeout: 30000,
                                      headers:{ 
                                          Accept: 'application/json',
                                          'Content-Type': 'application/json',
                                          authorization:tokenV
                                      }
                                  }).then((response)=&gt;{
                                      console.log(&quot;RESPONSE&quot;)
                                      console.log(response);
                                  })
                                  .catch(error=&gt;{
                                      console.log(&quot;ERROR&quot;)
                                      console.log(error);
                                  })
                                  // return fetch(this.props.apiurl+'/pushnotification/updatetoken', {
                                  //     method: 'PUT',
                                  //     headers: {
                                  //         Accept: 'application/json',
                                  //         'Content-Type': 'application/json',
                                  //     },
                                  //     body: JSON.stringify({
                                  //         email: email,
                                  //         pntoken: token,
                                  //     }),
                                  // })
                                  // .then((response) =&gt; {
                                  //     console.log('222222222222'); 
                                  //     console.log(response);
                                  //     response.json()
                                  // })
                                  // .then((responseJson) =&gt; {
                                  //     console.log('kkkkkkkkkkkkkkk'); 
                                  //     console.log(responseJson);
                                  // })
                                  // .catch((error) =&gt; {
                                  //     console.log('error'); 
                                  //     console.log(error);
                                  // });
                              }
                          });
                      }
                  });
              }
          });
      }
      
      async requestCameraPermission() {
          try {
              const granted = await PermissionsAndroid.request(
                  PermissionsAndroid.PERMISSIONS.CAMERA,{
                      'title': 'Camera Permission',
                      'message': 'needs access to your camera '
                  }
              )
              if (granted) {
                  console.log(&quot;You can use the camera&quot;)
                  this.requestLocationPermission()
              } 
              else {
                  console.log(&quot;Camera permission denied&quot;)
              }
          } catch (err) {
              console.warn(err)
          }
      }
  
      async requestLocationPermission() {
          try {
              const granted = await PermissionsAndroid.request(
                  PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
                  {
                      'title': 'Camera Permission',
                      'message': 'needs access to your location '
                  }
              )
              if (granted) {
                  console.log(&quot;You can use the location&quot;)
              } 
              else {
                  console.log(&quot;location permission denied&quot;)
              }
          } 
          catch (err) {
              console.warn(err)
          }
      }
  
      componentDidMount() {
          console.log(this.state);
          console.log(&quot;login componentDidMount&quot;);
          this.getfcmtooken();
          NetInfo.fetch().then((connectionInfo) =&gt; {
              if(connectionInfo.type != 'none'){
                  console.log(&quot;NETINFO&quot;);
                  this.setState({ checkinternet : false ,nointernet : false });
                  this.requestCameraPermission();
              }
              else{
                  this.setState({ checkinternet : false ,nointernet : true });
              }
          })
          .catch((response)=&gt;{
              console.log(response);
          });
          
          AppState.addEventListener('change', this._handleAppStateChange);
  
          this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this.keyboardDidShow.bind(this))
          this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this.keyboardDidHide.bind(this))
      }
  
      _handleAppStateChange = (nextAppState) =&gt; {
          console.log(&quot;CHECKING STATE&quot;);
          if (this.state.appState.match(/active/) &amp;&amp; nextAppState === 'background') {
            console.log('App has come to the background!')
          }
          console.log(&quot;CHECKED STATE&quot;)
          this.setState({appState: nextAppState});
          console.log(&quot;NEW STATE SET&quot;);
          NetInfo.fetch()
          .then((connectionInfo) =&gt; {
              if(connectionInfo.type != 'none'){
                  this.setState({ nointernet : false });
              }
              else{
                  this.setState({ nointernet : true });
              }
          })
          .catch((response)=&gt;{
              console.log(response);
          });
      }
  
      handleConnectivityChange() {
          
          NetInfo.fetch().then((connectionInfo) =&gt; {
              if(connectionInfo.type != 'none'){
                  console.log(&quot;INTERNET CHECK 1&quot;)
                  this.setState({ nointernet : false });
                  console.log(&quot;INTERNET CHECKED 1&quot;)
              }
              else{
                  console.log(&quot;INTERNET CHECK 2&quot;)
                  this.setState({ nointernet : true });
                  console.log(&quot;INTERNET CHECKED 2&quot;)
              }
          })
          .catch((response)=&gt;{
              console.log(response);
          });
      }
  
      componentWillUnmount() {
          AppState.removeEventListener('change', this._handleAppStateChange);
          NetInfo.removeEventListener('connectionChange', this.handleConnectivityChange );
          // unsubscribe();
          this.keyboardDidShowListener.remove()
          this.keyboardDidHideListener.remove()
      }
  
      keyboardDidShow (e) {
          console.log('Key Event');
          console.log(Dimensions.get('window').height+' - '+e.endCoordinates.height);
          let newSize = Dimensions.get('window').height - e.endCoordinates.height
          console.log('new size')
          console.log(newSize);
          console.log('wind_width')
          console.log(Dimensions.get('window').width);
          LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
          this.setState({
              visibleHeight: newSize,
              logo_width:50,
              logo_height:50
          })
      }
    
      keyboardDidHide (e) {
          LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
          this.setState({
              visibleHeight: Dimensions.get('window').height,
              logo_height:100,
              logo_width:100
          })
      }  
  
      managePwd(){ 
          this.setState({
              hidePwd:!this.state.hidePwd
          })
      }
  
      login(){
          if(this.state.username != ''){
              let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ ;
              if(reg.test(this.state.username) === true){
                  if(this.state.passwd != ''){
                      return fetch(this.props.apiurl+'/mobilelogin', {
                          method: 'POST',
                          headers: {
                              Accept: 'application/json',
                              'Content-Type': 'application/json',
                          },
                          body: JSON.stringify({
                              email: this.state.username,
                              password: this.state.passwd,
                              pntoken: this.state.pntoken,
                          }),
                      })
                      .then((response) =&gt; response.json())
                      .then((responseJson) =&gt; {
                          if(responseJson.statusCode == 200){
                                  this.setState({
                                  isLoading: false,
                                  text: responseJson.result.authenticateUser.userRole,
                                  dataSource: responseJson
                              }, function() {
                                  try{
                                      console.log('TOKEN');
                                      console.log(JSON.stringify(responseJson.result.authenticateUser.token));
                                      AsyncStorage.setItem('token', JSON.stringify(responseJson.result.authenticateUser.token)); 
                                      AsyncStorage.setItem('email', JSON.stringify(responseJson.result.authenticateUser.email)); 
                                      AsyncStorage.setItem('userRole', JSON.stringify(responseJson.result.authenticateUser.userRole)); 
                                      AsyncStorage.setItem('org_id', JSON.stringify(responseJson.result.authenticateUser.orgId)); 
                                      AsyncStorage.setItem('user_id', JSON.stringify(responseJson.result.authenticateUser.userId)); 
                                      this.getfcmtooken();
                                      AppState.removeEventListener('change', this._handleAppStateChange);
                                      unsubscribe();
                                      // NetInfo.removeEventListener('connectionChange', this.handleConnectivityChange );
                                      Actions.landing();
                                  } catch (error) {
                                      console.log(error)
                                  }
                              });
                          }
                          else{
                              ToastAndroid.show(responseJson.authenticateUser.statusMessage,ToastAndroid.LONG);
                          }
                      })
                      .catch((error) =&gt; {
                          console.log('error'); 
                          console.log(error);
                      });
                  }
                  else{
                    ToastAndroid.show('Password is mandatory',ToastAndroid.LONG);
                  }
              }
              else{
                ToastAndroid.show('Email is not in correct form',ToastAndroid.LONG);
              }
          }
          else{
              ToastAndroid.show('Email is mandatory',ToastAndroid.LONG);
          }
      }
  
      render(){
          console.log(&quot;RENDERING ...&quot;);
          if(this.state.checkinternet){
              console.log(&quot;LOADING...CONNECTION &quot;)
              return  &lt;View style={{flex:1, backgroundColor: '#fff'}}&gt;
                          &lt;View style={{height:screenHeigth-60, justifyContent:'center',alignItems:'center'}}&gt;
                              &lt;Bars size={25} color=&quot;#eb5828&quot; /&gt;
                          &lt;/View&gt;
                      &lt;/View&gt;;
          }
          if (this.state.nointernet) {
              return  &lt;View&gt;
                          &lt;Nointernet/&gt;
                      &lt;/View&gt;;
          }
          return (
                  &lt;View style={[styles.container,{height: this.state.visibleHeight}]}&gt;
                      &lt;ImageBackground
                        style={[styles.topLogo1,{height: this.state.visibleHeight}]}
                        source={require('../assets/Background.png')}
                      &gt;
                          &lt;View style={styles.upperContainer}&gt;
                              &lt;View style={styles.signintextContainer}&gt;
                                  &lt;Image style={{height:this.state.logo_height,width:this.state.logo_width}} source={require('../assets/WhiteLogo.png')}/&gt;
                                  &lt;Text style={styles.appname}&gt;Smart Timer&lt;/Text&gt;
                              &lt;/View&gt;
                          &lt;/View&gt;
                          &lt;View style={styles.formContainer}&gt;
                              &lt;View style={[{width:elementWidth},styles.elementcontainer]}&gt;
                                  &lt;TextField 
                                      label={'E-mail ID'} 
                                      highlightColor={'#fff'} 
                                      onChangeText={(username) =&gt; this.setState({username})}
                                      value={this.state.username}
                                      keyboardType='email-address'
                                      autoCapitalize='none'
                                      textColor='#fff'
                                      wrapperStyle={{ height: 60 }}
                                      labelStyle={{ color: '#fff', fontFamily: 'Lato-Regular' }}
                                  /&gt;
                              &lt;/View&gt;
                              &lt;View style={[{width:elementWidth},styles.elementcontainer]}&gt;
                                  &lt;View style={styles.textBoxBtnHolder}&gt;
                                      &lt;TextField 
                                          label={'Password'} 
                                          highlightColor={'#fff'} 
                                          secureTextEntry={this.state.hidePwd}
                                          onChangeText={(passwd) =&gt; this.setState({passwd})}
                                          value={this.state.passwd}
                                          autoCapitalize='none'
                                          textColor='#fff'
                                          wrapperStyle={{ height: 60 }}
                                          labelStyle={{ color: '#fff', fontFamily: 'Lato-Regular' }}
                                      /&gt;
                                      &lt;TouchableOpacity style={styles.visibilityBtn} onPress={this.managePwd.bind(this)} &gt;
                                          &lt;Image style={{ marginRight:10, height: 25,width: 25 }} source={this.state.hidePwd?require('../assets/private.png'):require('../assets/view.png')}/&gt;
                                      &lt;/TouchableOpacity&gt;
                                  &lt;/View&gt;
                              &lt;/View&gt;
                              &lt;TouchableOpacity style={[ {width:elementWidth},styles.buttonRaised ]} onPress={this.login.bind(this)} &gt;
                                  &lt;Text style={[ styles.buttonText ]}&gt;Login&lt;/Text&gt;
                              &lt;/TouchableOpacity&gt;
                              &lt;View style={styles.signupTextContainer}&gt;
                                  &lt;View&gt;
                                      &lt;TouchableOpacity onPress={() =&gt; Actions.forgotpassword({apiurl:this.props.apiurl})} &gt;
                                          &lt;Text style={[ styles.signupText ]}&gt;Forgot Password  | &lt;/Text&gt;
                                      &lt;/TouchableOpacity&gt;
                                  &lt;/View&gt;
                                  &lt;View&gt;
                                      &lt;TouchableOpacity onPress={() =&gt; Actions.register({apiurl:this.props.apiurl})} &gt;
                                          &lt;Text style={[ styles.signupTextblack ]}&gt; Sign Up&lt;/Text&gt;
                                      &lt;/TouchableOpacity&gt;
                                  &lt;/View&gt;
                              &lt;/View&gt;
                          &lt;/View&gt;
                      &lt;/ImageBackground&gt;
                  &lt;/View&gt;
              );
      }
  }
  </code></pre>
  <p>I had this code running fine before I upgraded from react-native 0.56.0 to 0.60.4 and also I upgraded react-native-router-flux from ^4.0.0-beta.28 to ^4.0.6. Not very sure if this piece of information helps.</p>