title: React-native TypeError: Cannot read property 'data' of undefined
body: <p>I have propblems in my project
  <a href="https://i.stack.imgur.com/AR2lA.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  
  <blockquote>
    <p>D:\React-Native\Expo\mobile\node_modules\expo\build\logs\RemoteConsole.js:80 Possible Unhandled Promise Rejection (id: 0):
    TypeError: Cannot read property 'data' of undefined
    TypeError: Cannot read property 'data' of undefined</p>
  </blockquote>
  
  <p><strong>SignUp.js</strong></p>
  
  <pre><code>import React from 'react';
  import {ScrollView, KeyboardAvoidingView, CheckBox, View, Text, Platform,} from 'react-native';
  import styles from './styles/authStyles';
  import ScreenTitle from '../components/ScreenTitle';
  import Input from '../components/input';
  import Button from '../components/Button';
  import axios from '../config/axios';
  import { SINGNUP_URL } from '../config/urls';
  import Loader from '../components/Loader';
  import Alert from '../components/Alert';
  export default class SignUpScreen extends React.Component
  {
  constructor(props) 
  {
      super(props);
      this.state =
      {
          name: "",
          email: "",
          password: "",
          specialization: "",
          phone: "",
          address: "",
          workingHours: "",
          userType: false,
          location: null,
          isLoading: false,
          alert:
          {
              messages: null,
              type: "",
          }
      }
  }
  componentDidUpdate()
  {
      if(this.state.alert.messages)
      {
          setTimeout(() =&gt;
          {
              this.setState({alert: {messages: null}})
          }, 3000)
      }
  }
  componentWillUnMount()
  {
      clearTimeout();
  }
  changeNameHandler = (value) =&gt;
  {
      this.setState({name: value})
  };
  
  changeEmailHandler = (value) =&gt;
  {
      this.setState({email: value})
  };
  
  changePasswordHandler= (value) =&gt;
  {
      this.setState({password: value})
  };
  
  changeSpecializationHandler = (value) =&gt;
  {
      this.setState({specialization: value})
  };
  
  changePhoneHandler = (value) =&gt;
  {
      this.setState({phone: value})
  };
  
  changeAddressHandler = (value) =&gt;
  {
      this.setState({address: value })
  };
  
  changeWorkingHoursHandler = (value) =&gt;
  {
      this.setState({workingHours: value})
  };
  
  changeUserTypeHandler = () =&gt;
  {
      this.setState({ userType: !this.state.userType})
  }
  validate() 
  {
      const {name, email, password, specialization, address, phone, workingHours, userType} = this.state;
      let validationErrors = [];
      let passed = true;
      if(!name) 
      {
          validationErrors.push(" Please put your name");
          passed= false;
      }
      if(!email) 
      {
          validationErrors.push(" Please put your email");
          passed= false;
      }
      if(!password) 
      {
          validationErrors.push(" Please put your password");
          passed= false;
      }
      if(userType)
      {
          if(!specialization) 
          {
              validationErrors.push(" Please put your specialization");
              passed= false;
          }
          if(!address) 
          {
              validationErrors.push(" Please put your address");
              passed= false;
          }
          if(!phone) 
          {
              validationErrors.push(" Please put your phone nuber");
              passed= false;
          }
          if(!workingHours) 
          {
              validationErrors.push(" Please put your working hours");
              passed= false;
          }
      }
      if(validationErrors.length &gt; 0)
      {
          this.setState({alert: {messages: validationErrors, type: "danger"}})
      }
      return passed
  }
  
  _SignUp = async () =&gt;
  {
      if(!this.validate()) return;
      this.setState({isLoading: true})
      const { name, email, password, specialization, address, phone, workingHours, userType } = this.state;
      const body =
      {
          name, 
          email, 
          password, 
          specialization, 
          address, 
          phone, 
          workingHours, 
          userType: userType ? "doctor" : 'normal',
          location:
          {
              latitude: 1,
              longitude: 2
          },
          isLoading: false
      }
      try 
      {
          const response = await axios.post(SINGNUP_URL, body);
          this.setState({
              name:'',
              email: '',
              password: '',
              specialization: '',
              address: '',
              phone: '',
              workingHours: '',
              userType: false,
              location: null
  
          });
          this.props.navigation.navigate("SignIn",
          {
              alert:{messages:"Your account has been successfully registered", type:"success"}
          });
      } 
      catch(e){
          this.setState({
              alert: { messages: e.response.data.message, type: "danger"},
              isLoading: false
          });
  
      }
  
  
  
  
  }
  
  render()
  {
      const { name, email, password, specialization, address, phone, workingHours, userType, isLoading, alert } = this.state;
      return(
          &lt;ScrollView contentContainerStyle={{paddingVertical: 40}}&gt;
              &lt;Loader title="A new account is creating" loading={isLoading} /&gt;
              &lt;Alert messages={alert.messages} type={alert.type} /&gt;
              &lt;View style={styles.container}&gt;
                  &lt;ScreenTitle 
                      title="Create new account"
                      icon="md-person-add"
                  /&gt;
                  &lt;KeyboardAvoidingView behavior="padding" enabled &gt;
  
                      &lt;Input 
                          placeholder="Name" 
                          onChangeText={this.changeNameHandler}
                          value={name} /&gt;
  
                      &lt;Input 
                          placeholder="Email" 
                          onChangeText={this.changeEmailHandler}
                          value={email} /&gt;
  
                      &lt;Input 
                          placeholder="Password" 
                          secureTextEntry
                          onChangeText={this.changePasswordHandler}
                          value={password} /&gt;
  
                      &lt;View 
                          style={styles.checkBoxContainer}
                          &gt;
                          &lt;CheckBox 
                              style={styles.checkBoxLabel} 
                                  value={userType} 
                                  onChange={this.changeUserTypeHandler} /&gt;
  
                          &lt;Text style={styles.checkBoxLabel} &gt;Doctors&lt;/Text&gt;
  
                      &lt;/View&gt;
                      {userType &amp;&amp; (
                          &lt;React.Fragment&gt;
                              &lt;Input 
                                  onChangeText={this.changeSpecializationHandler}
  
                                  placeholder="Specialization" value = {specialization} /&gt;
  
                              &lt;Input 
                                  onChangeText={this.changeWorkingHoursHandler}
  
                                  placeholder="Hours work"  value={workingHours} /&gt;
  
                              &lt;Input 
                                  onChangeText={this.changeAddressHandler}
  
                                  placeholder="Address" value={address} /&gt;
  
                              &lt;Input 
                                  onChangeText={this.changePhoneHandler}
                                  placeholder="Phone Number" value={phone} /&gt;
                          &lt;/React.Fragment&gt;
                      )}
  
  
                      &lt;Button 
                          text="New Account" 
                          onPress={this._SignUp}
                      /&gt;
                      &lt;View style={{height: 30}} /&gt;
                      {/* &lt;Button text="Home" onPress={() =&gt; this.props.navigation.navigate("Main")} /&gt;    */}
                  &lt;/KeyboardAvoidingView&gt;
              &lt;/View&gt;
          &lt;/ScrollView&gt;
      )
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>SignIn.js</strong></p>
  
  <pre><code>import React, { Component } from 'react'
  import { Text, View, KeyboardAvoidingView, AsyncStorage } from 'react-native'
  import styles from './styles/authStyles';
  import ScreenTitle from '../components/ScreenTitle';
  import Input from '../components/input';
  import Button from '../components/Button';
  import axios from '../config/axios';
  import { SIGNIN_URL } from '../config/urls';
  import Loader from '../components/Loader';
  import Alert from '../components/Alert';
  import Container from '../components/Container';
  import { ScrollView } from 'react-native-gesture-handler';
  export default class SignIn extends Component {
  
  constructor(props)
  {
      super(props);
      this.state =
      {
          email: "",
          password: "",
          isLoading: false,
          alert:
          {
              messages: null,
              type: ""
          }
      }
  }
  
  componentDidMount()
  {
      const alert = this.props.navigation.getParam('alert');
      if(alert)
      {
          this.setState({alert});
      }
  }
  componentDidUpdate()
  {
      if(this.state.alert.messages)
      {
          setTimeout(() =&gt;
          {
              this.setState({alert: {messages: null}})
          }, 3000)
      }
  }
  componentWillUnMount()
  {
      clearTimeout();
  }
  
  changeEmailHandler = (value) =&gt;
  {
      this.setState({email: value})
  };
  
  changePasswordHandler= (value) =&gt;
  {
      this.setState({password: value})
  };
  
  validate() 
  {
      const { email, password } = this.state;
      let validationErrors = [];
      let passed = true;
  
      if(!email) 
      {
          validationErrors.push(" Please put your email");
          passed= false;
      }
      if(!password) 
      {
          validationErrors.push(" Please put your password");
          passed= false;
      }
  
      if(validationErrors.length &gt; 0)
      {
          this.setState({alert: {messages: validationErrors, type: "danger"}})
      }
      return passed
  }
  _SignIn= async () =&gt; {
      if(!this.validate()) return;
  
      this.setState({ isLoading: true });
  
      const body = {
          email: this.state.email,
          password: this.state.password
      };
  
      try {
          const response = await axios.post(SIGNIN_URL, body);
          this.setState({ email: "", password: "", isLoading: false });
          AsyncStorage.setItem("accessToken", response.data.accessToken);
      } catch (e) {
          this.setState({
              alert: { messages: e.response.data.message, type: "danger" },
              isLoading: false
          });
      }
  }
  render() {
      const {email, password, isLoading, alert} = this.state;
      return (
          &lt;Container&gt;
              &lt;Alert messages={alert.messages} type={alert.type} /&gt;
              &lt;Loader title="Login" loading={isLoading} /&gt;
              &lt;ScrollView
              keyboardShouldPersistTaps="handled"
              contentContainerStyle={styles.container} &gt;
                  &lt;ScreenTitle title="Login" icon="md-log-in" /&gt;
                  &lt;KeyboardAvoidingView behavior="padding" enabled&gt;
                      &lt;Input 
                      onChangeText={this.changeEmailHandler}
                      value={email}
                      placeholder="Email" /&gt;
                      &lt;Input 
                      onChangeText={this.changePasswordHandler}
                      value={password}
                      secureTextEntry
                      placeholder="Password" /&gt;
                  &lt;/KeyboardAvoidingView&gt;
                  &lt;Button 
                   text="Login"
                   onPress={this._SignIn} 
                  /&gt;
                  &lt;View style={{height: 30}} /&gt;
                  {/* &lt;Button text="Home" onPress={() =&gt; this.props.navigation.navigate("Main")} /&gt; */}
  
              &lt;/ScrollView&gt;
          &lt;/Container&gt;
      )
  }
  }
  </code></pre>