首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何解决固定冲突:文本字符串必须在React Native中的<Text>组件中呈现?

如何解决固定冲突:文本字符串必须在React Native中的<Text>组件中呈现?
EN

Stack Overflow用户
提问于 2019-03-05 08:42:17
回答 2查看 1.8K关注 0票数 1

在我的React- Native项目中,我安装了以下版本的react-navigation:

npm安装react-navigation@^1.0.0-beta.11

然后运行以下命令:

npm安装

在所有这些安装之后,我已经创建了一个名为WelcomeScreen.js的类,下面是它的代码-

WelcomeScreen.js

代码语言:javascript
复制
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

代码语言:javascript
复制
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

他们没有一个对我有帮助。所以,如果有人能帮我解决这个问题,那就太好了。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54993769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档