Hi Im trying to make my own login screen for my app and im getting this error.
It says the error is located at:
in Login (at App.js:12)
This is my Login.js:
import React, { Component } from "react";
import { View, Text } from "react-native";
import { Header, Card, CardSection, Input, Button, Spinner } from "../components";
import PasswordTextInput from "../components/PasswordTextInput";
class Login extends Component {
state = { email: "", password: "", error: "", loading: false };
onButtonPress() {
const { email, password } = this.state;
if (email.length === 0 || password.length === 0) {
this.setState({
error: "Please enter valid credential",
loading: false
})
}
else {
this.setState({ error: "", loading: true });
}
}
onLoginFail() {
this.setState({
error: "Authentication Failed",
loading: false
});
}
onLoginSuccess() {
this.setState({
email: "",
password: "",
loading: false,
error: ""
});
}
renderButton() {
if (this.state.loading) {
return <Spinner size="small" />;
}
return <Button onPress={this.onButtonPress.bind(this)}>Log in</Button>;
}
renderError() {
if (this.state.error.length > 0) {
return <Text style={styles.errorStyle}>{this.state.error}</Text>
}
}
render() {
return (
<View>
<Header title="Login" />
<Card>
<CardSection>
<Input
placeholder="Enter Email"
label="Email"
value={this.state.email}
onChangeText={email => this.setState({ email })}
/>
</CardSection>
<CardSection>
<PasswordTextInput
placeholder="Enter Password"
label="Password"
value={this.state.password}
onChangeText={password => this.setState({ password })}
/>
</CardSection>
{this.state.error.length > 0 && <Text style={styles.errorStyle}>{this.state.error}</Text>}
<CardSection>{this.renderButton()}</CardSection>
</Card>
</View>
);
}
}
const styles = {
errorStyle: {
fontSize: 18,
alignSelf: "center",
color: "red",
padding: 5
}
};
export default Login;
And this is my App.js:
import React, { Component } from 'react';
import {
AppRegistry
} from 'react-native';
import Login from './src/pages/Login';
export default class App extends Component {
render() {
return (
<Login />
);
}
}
AppRegistry.registerComponent('App', () => App);
I have read about some of the solutions regarding this similar problems and it was said that I am calling a function that calls the another function and back and forth thus it hits the limit.
Maximum call stack size exceeded error
Could you go through my code and tell me what change I have to make to the Login.js file?