【发布时间】:2020-06-27 23:22:32
【问题描述】:
错误信息是:
Invariant Violation:元素类型无效,期望字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义
我是新来的反应,找不到代码有什么问题。错误消息告诉我“检查'LoginScreen'的渲染方法”。
我的代码:
// Import React Navigation
import {
createBottomTabNavigator,
createStackNavigator,
} from 'react-navigation';
import tabBarIcon from './utils/tabBarIcon';
// Import the screens
import FeedScreen from './screens/FeedScreen';
import NewPostScreen from './screens/NewPostScreen';
import SelectPhotoScreen from './screens/SelectPhotoScreen';
import React, {Component, Button} from 'react';
/*export default class App extends Component<Props> {
render(){
<View>
</View>
}
}*/
class LoginScreen extends Component {
login() {
this.props.navigation.navigate('Main');
}
render() {
return <Button title='Login' onPress={() => {this.login()}} />;
}
}
// Create our main tab navigator for moving between the Feed and Photo screens
const navigator = createBottomTabNavigator(
{
// The name `Feed` is used later for accessing screens
Feed: {
// Define the component we will use for the Feed screen.
screen: FeedScreen,
navigationOptions: {
// Add a cool Material Icon for this screen
tabBarIcon: tabBarIcon('home'),
},
},
// All the same stuff but for the Photo screen
Photo: {
screen: SelectPhotoScreen,
navigationOptions: {
tabBarIcon: tabBarIcon('add-circle'),
},
},
},
{
// We want to hide the labels and set a nice 2-tone tint system for our tabs
tabBarOptions: {
showLabel: false,
activeTintColor: 'black',
inactiveTintColor: 'gray',
},
},
);
// Create the navigator that pushes high-level screens like the `NewPost` screen.
const stackNavigator = createStackNavigator(
{
Main: {
screen: navigator,
// Set the title for our app when the tab bar screen is present
navigationOptions: { title: 'Insta' },
},
// This screen will not have a tab bar
NewPost: NewPostScreen,
},
{
cardStyle: { backgroundColor: 'white' },
},
);
const TopLevelNav = createStackNavigator({
Login: { screen: LoginScreen },
Main: { screen: stackNavigator },
}, {
headerMode: 'none',
});
// Export it as the root component
export default TopLevelNav;
【问题讨论】:
标签: reactjs react-native