XHR error: loading


#1

am getting “XHR error”. pls help.

code
//import re-usable lib
import React, { Component } from ‘react’;
import { Text } from ‘react-native’;
import { Button, Card, CardSection, Field, Spinner } from ‘./common/’;
import firebase from ‘firebase’;

//create component
class LoginForm extends Component {
state = {
email: ‘’,
password: ‘’,
error: ‘’,
loading: false,
};

showSpinner() {
if (this.state.loading) {
return ;
}
return Log in;
}

onPressButton() {
const { email, password } = this.state;
this.setState({
email: ‘’,
password: ‘’,
error: ‘’,
loading: true,
});

firebase
  .auth()
  .signInWithEmailAndPassword(email, password)
  .then(() => this.setState({ loading: false }))
  .catch(() => {
    firebase
      .auth()
      .createUserWithEmailAndPassword(email, password)
      .then(() => this.setState({ loading: false }))
      .catch(() => {
        this.setState({ error: 'Authentication failed', loading: false });
      });
  });

}
render() {
return (


<Field
label=“Email”
onChangeText={email => this.setState({ email })}
placeholder="example@mail.com"
value={this.state.email}
/>

    <CardSection>
      <Field
        label="Password"
        onChangeText={password => this.setState({ password })}
        placeholder="password"
        value={this.state.password}
        secureTextEntry
      />
    </CardSection>

    <Text style={styles.Field}>{this.state.error}</Text>

    <CardSection>{this.showSpinner()}</CardSection>
  </Card>
);

}
}

const styles = {
errorStyle: {
fontSize: 18,
color: ‘red’,
},
};

//make it available
export default LoginForm;

end code*


#2

Hey @aditya-08,

It’s a bit hard to read the code snippets below, can you share the Snack you are running? At first glance, it looks like there may be an issue with your importing of the common components.

Cheers,

Adam


#3

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.