如何在React-Native中修复“路线'Principal'的组件必须是React组件”错误

Dejuanfran99

我是新来的反应母语和我以前遇到过这样的问题:(路由组件“委托人”必须是一个阵营component.For例如:...)

我想将DrawerNavigator放在StackNavigator中。我已经知道这是个好方法,但是它给了我我一直在寻找的错误,但我无法解决。

谢谢

App.js

import React, { Component } from 'react';
import {createAppContainer,createStackNavigator,createDrawerNavigator} from 'react-navigation';
import Login from './pantallas/login';
import Registro from './pantallas/registro';
import PantallaPrincipal from './pantallas/pantallaPrincipal';
import SolicitudCitas from './pantallas/socitudCitas';
import {Header,Icon} from 'native-base';

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

const AppStackNavigator = createStackNavigator({
  Login: { screen: Login },
  Registro: { screen: Registro },
  Principal: {screen: AppDrawerNavigator}
},{
  headerMode: 'none',
  navigationOptions: {
    headerVisible: false,
  }
}
);

const AppDrawerNavigator = createDrawerNavigator({
    PantallaPrincipal:{screen: PantallaPrincipal},
    SolicitudCitas: {screen: SolicitudCitas}}
    ,{
    defaultNavigationOptions: ({ navigation }) => {
        return {
          headerLeft: (
            <Header>
              <Icon
                style={{ paddingLeft: 10 }}
                onPress={() => navigation.openDrawer()}
                name="menu"
                size={30}/>
            </Header>
          )
        };
      }
    }
  );

const AppContainer = createAppContainer(AppStackNavigator);

pantallaPrincipal.js

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

export default class pantallaPrincipal extends Component {
    
  render() {
    return (
      <View style={styles.backgroundContainer}>
        <Text>Pantalla principal</Text>
      </View>
    );
  }
}


const styles = StyleSheet.create({
  backgroundContainer : {
    flex: 1,
    width: null,
    height: null,
    justifyContent: 'center',
    alignItems: 'center'
  }
});

solicitudCitas.js

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

export default class solicitudCitas extends Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
        <Text>Solicitud Citas</Text>
      </View>
    );
  }
}
Suraj Malviya

只需在要使用它的Stack导航器上方声明并初始化DrawerNavigator。这只是由于提升JS基础而发生的。在javascript中,只悬挂声明,而不初始化,因此,当您使用时Principal: {screen: AppDrawerNavigator},JS并不知道它AppDrawerNavigator实际上是一个React组件,因为在使用它之前没有对其进行初始化。您可以在此处学习有关JS吊装的更多信息

希望这可以帮助。编码愉快!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

路由的组件必须是React native expo中的react组件错误

路线''的组件必须是React组件

React Native 错误:路由的组件必须是 React 组件

修复错误:路线“家”的组件必须是一个React组件

React Native-路线'...'的组件必须是React组件

React Native Navigation Error:路线的组件必须是React组件

路线“ ActivityFeed”的组件必须是React组件

路线“ Main”的组件必须是React组件

React Native:如何在onPress期间修复Button组件的错误?

用于路由的组件必须是react native中的react组件

如何修复“路由HomeScreen的组件必须是React组件”

错误:路由“Home”的组件必须是 React 组件

反应本机导航-路线的组件必须由react组件

React Native错误:原始“”必须包装在显式的<Text>组件中

如何修复React-Native中的错误“您可能忘记了从文件..etc导出组件”错误?

如何在 React 中管理组件状态(加载、错误、数据)

如何在React Native中让组件控制同级组件?

react-country-region-selector 组件给定错误 文本字符串必须在 <Text> 组件中呈现

“ ReactJS中的组件之一”出现“必须返回有效的React元素(或null)”错误

路由组件必须是React组件

路由 '...' 的组件必须是 React 组件

错误:当字符串不为空时,文本字符串必须在 React Native 的 <Text> 组件中呈现

如何在React Native中修复Firebase / firestore错误?

如何在React Native中修复``错误:未知选项--projectRoot''

如何在 React 中构建专门的组件

如何在 React 中强制渲染组件

如何在 React 中返回组件

如何在 React 组件中传递道具?

如何在React组件中访问JSON?