React Native Invariant Violation:查看配置

时间:2017-10-15 00:06:26

标签: javascript android react-native

我试图在React Native项目上使用不同的屏幕练习。这是来自App.js文件的代码。

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View
} from 'react-native';

import { StackNavigator } from 'react-navigation';

class HomeScreen extends React.Component {
    static navigationOptions = {
        title: "welcome",
    };
    render() {
        return <Text style={{ color: 'black '}}>Hello, Navigation!</Text>;
    }
}

const navigation = StackNavigator({
    Home: { screen: HomeScreen },

});

export default class App extends Component<{}> {
  render() {
    return <navigation/>;
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
  },
});

当我运行react-native run-android时,我收到一个Invariant Violation,告诉我&#34;查看未找到的配置或命名导航&#34;。然后是发生此违规行为的所有网站。 请帮助谢谢。

2 个答案:

答案 0 :(得分:127)

任何组件的名称必须大写。在您的名称中,组件“navigation”不是大写的。它应该是“导航”。

答案 1 :(得分:1)

在本机中,组件的名称应以大写字母开头,因此它将是:

# just first few lines for illustration
Lines <- '
replace class = "ACE Inhibitor" if strmatch(upper(drug), "CAPTOPRIL*")
replace class = "ACE Inhibitor" if strmatch(upper(drug), "ENALAPRIL*")
replace class = "ACE Inhibitor" if strmatch(upper(drug), "ENALAPRILAT*")
'

Lines2 <- "
id       drug        start        stop          dose    unit    route   
2010003  Amlodipine  2009-02-04   2009-11-19    1.5     mg      Oral    
2010003  Amlodipine  2009-11-19   2010-01-11    1.5     mg      Oral      
2010004  Cefprozil   2004-03-12   2004-03-19    175     mg      Oral    
2010004  Clobazam    2002-12-30   2003-01-01    5       mg      Oral"

statascript <- readLines(textConnection(Lines))
DF <- read.table(text = Lines2, header = TRUE, as.is = TRUE)

并用资本称呼它:

const Navigation = StackNavigator({
    Home: { screen: HomeScreen },

});