在我的React- Native项目中,我安装了以下版本的react-navigation:
npm安装react-navigation@^1.0.0-beta.11
然后运行以下命令:
npm安装
在所有这些安装之后,我已经创建了一个名为WelcomeScreen.js的类,下面是它的代码-
WelcomeScreen.js
import React, { Component } from "react";
import {
View,
StyleSheet,
Button
} from "react-native";
class WelcomeScreen extends Component {
static navigationOptions = {
header: 'none'
}
render() {
return (
<View style={styles.container}>
<Button title="Log in" onPress={() => this.props.navigation.navigate('LoginScreen')}/>
<Button title="Sign Up" onPress={() => this.props.navigation.navigate('SignUpScreen')}/>
</View>
)
}
}
export default WelcomeScreen;
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center'
}
});
在那之后,我在我的App.js文件中路由了这个类。下面是给出的代码:
App.js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { StackNavigator } from 'react-navigation'
import WelcomeScreen from './screens/WelcomeScreen'
export default class App extends React.Component {
render() {
return (
<AppStackNavigator/>
);
}
}
const AppStackNavigator = new StackNavigator({
WelcomeScreen: { screen: WelcomeScreen }
})
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
然后在运行我的项目后,我一直收到这个错误:
不变冲突:必须在组件中呈现文本字符串
Invarient violation:Text strings must be rendered within a component
我不明白为什么我会得到这个错误?我尝试了以下解决方案-
Invariant Violation: Text strings must be rendered within a component
https://github.com/facebook/react-native/issues/20084
他们没有一个对我有帮助。所以,如果有人能帮我解决这个问题,那就太好了。
https://stackoverflow.com/questions/54993769
复制相似问题