Search code examples
react-nativereact-android

TypeError: expected dynamic type `string', but had type `int64' while getting text from TextInout


Here is my I tried a but not able to resolve this simple one

export default class LoginScene extends Component {
    constructor(props) {
        super(props);
        this.state = {
             userid: '',
             password: '',

        };
    }

    componentWillMount() {

        // this.fetchData();
    }




    veryfyLogin() {

        fetch(LOGIN_URL)
            .then((response) => {
                if (response.status === 200) {
                    var navigator = this.props.navigator;
                    navigator.push({
                        id: 'dashboard',
                        title: 'DashBoardScene',
                        index: 1
                    });
                }

             Alert.alert(response.status);
                 })
            .done();

    }


    render() {
        onButtonPress = () => {
           Alert.alert("userid:::"+this.state.userid+"Password:::"+this.state.password);
            this.veryfyLogin();

    };

        return (

            <View  >

                <Text> User Name: </Text>

                <TextInput
                    style={{ height: 40 }}
                    ref= {(el) => { this.userid = el; }}
                    placeholder="enter your email address"
                    onChangeText={(userid) => this.setState({ userid })}
                    value={this.state.userid}
                    />

                <Text> Password: </Text>

                <TextInput
                    ref= {(el) => { this.password = el; }}
                    style={{ height: 40 }} password={true}
                    placeholder="password"
                    onChangeText={(password) => this.setState({ password })}
                    value={this.state.password}
                    />

                <Button
                    title="Login"
                    color="#841584"
                    onPress={onButtonPress}
                    accessibilityLabel="Learn more about purple"
                    />
            </View>

        )
    }
}

LoginScene.propTypes = {
    title: PropTypes.string.isRequired,
    // onForward: PropTypes.func.isRequired,
    // onBack: PropTypes.func.isRequired,
};



AppRegistry.registerComponent('LoginScene', () => LoginScene);

Solution

  • There is small mistake in the code

    veryfyLogin() {
    
            fetch(LOGIN_URL)
                .then((response) => {
                    if (response.status === 200) {
                        var navigator = this.props.navigator;
                        navigator.push({
                            id: 'dashboard',
                            title: 'DashBoardScene',
                            index: 1
                        });
                    }
    

    Alert.alert(response.status);

                     })
                .done();
    
        }
    

    The Alert.alert(response.status); expecting an String but here the response.status is an integer after adding Alert.alert(response.status+"); it worked for me.