我遇到以下错误:
不变违规:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到了:对象。您可能忘记了从定义文件中导出组件。
有人可以帮助我弄清楚我的错误在哪里吗?
这是我的代码:
import React from 'react';
import {View, Button, Text} from 'react-native';
import * as firebase from 'firebase';
import HomeScreen from '../components/HomeScreen';
import {createStackNavigator} from 'react-navigation';
import {FormLabel, FormInput} from 'react-native-elements';
export default class Login extends React.Component {
constructor(props){
super(props);
this.state = {email:'', password:'', error:'', loading: false};
}
onLoginPress(){
this.setState({error:'', loading: true});
const {email, password} = this.state;
firebase.auth().signInWithEmailAndPassword(email, password)
.then(() => {
this.setState({error:'', loading: false})
this.props.navigation.navigate('HomeScreen')
})
.catch(() =>{
this.setState({error:'Authentication failed', loading: false});
})
}
onSignUpPress(){
this.setState({error:'', loading: true});
const {email, password} = this.state;
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(() => {
this.setState({error:'', loading: false})
this.props.navigation.navigate('HomeScreen')
})
.catch(() =>{
this.setState({error:'Authentication failed', loading: false});
})
}
renderButtonOrLoading(){
if(this.state.loading){
return <Text> Loading </Text>
}
return <View>
<Button
onPress={this.onLoginPress.bind(this)}
title='Login'/>
<Button
onPress={this.onSignUpPress.bind(this)}
title='Sign Up'/>
</View>
}
render(){
return(
<View>
<Label> Email </Label>
<Input
label={"Login"}
value={this.state.email}
placeholder='john@gmail.com'
onChangeText={email => this.setState({email})}/>
<Label> Password </Label>
<Input
label={"Login"}
value={this.state.password}
secureTextEntry
placeholder='********'
onChangeText={password => this.setState({password})}/>
<Text>{this.state.error}</Text>
{this.renderButtonOrLoading()}
</View>
)
}
}
这是错误:
答案 0 :(得分:1)
我设法将其与以下代码一起使用:
import React from 'react';
import {View} from 'react-native';
import {Input} from 'react-native-elements';
export default class FormExample extends React.Component {
render(){
return(
<View>
<Input
label={"Login"}/>
</View>
)
}
}