javascript - 每个模块只有一个默认导出允许使用 Navbar 在 React Native 上出错

标签 javascript react-native error-handling

我正在尝试使用带有图标的 React Native 制作底部导航栏,但出现此错误每个模块只允许一个默认导出。
问题来自最后一行 export default createAppContainer(TabNavigator);
我尝试以这种方式导出默认 createAppContainer(TabNavigator)(Home) 并将导出默认值删除到我的 Home.js 组件,但它也不起作用。
有谁知道我做错了什么。欢迎所有帮助!

import React, {Component} from 'react'
import {Text, View, StyleSheet } from 'react-native';
import {createBottomTabNavigator, createAppContainer } from 'react-navigation';
import {createMaterialBottomTabNavigator} from 'react-navigation-material-bottom-tabs';
import {Icon} from 'react-native-elements';

import Profile from "./Profile";
import Appointment from "./Appointment";



const styles = StyleSheet.create({

   homeText: {
      fontSize: 40,
      
   },

   homeCont: {
      flex: 1,
      justifyContent: "center",
      alignItems: "center"
   }

})

export default class Home extends Component {

   render() {

      return(

         <View style={styles.homeCont}>
            <Text style={styles.homeText}>HOME SCREEN</Text>
            
         </View>
    
     
      )

   }

   

}

const TabNavigator= createMaterialBottomTabNavigator({

   Home: {screen:Home,
          navigationOptions: {
             tabBarLabel: 'Home',
             activeColor: '#ff0000',
             inactiveColor: '#000000',
             barStyle: {backgroundColor: '#67baf6'},
             tabBarIcon:() => (
                <View>
                   <Icon name={'home'} size={25} style={{color:'#ff000'}} />
                </View>
             )
          }
   },
   Appointment: {screen:Appointment,
      navigationOptions: {
         tabBarLabel: 'Appointment',
         activeColor: '#ff0000',
         inactiveColor: '#000000',
         barStyle: {backgroundColor: '#67baf6'},
         tabBarIcon:() => (
            <View>
               <Icon name={'calendar'} size={25} style={{color:'#ff000'}} />
            </View>
         )
      }
},

Profile: {screen:Profile,
   navigationOptions: {
      tabBarLabel: 'Profile',
      activeColor: '#ff0000',
      inactiveColor: '#000000',
      barStyle: {backgroundColor: '#67baf6'},
      tabBarIcon:() => (
         <View>
            <Icon name={'person'} size={25} style={{color:'#ff000'}} />
         </View>
      )
   }
}


});

export default createAppContainer(TabNavigator);

最佳答案

问题是您正在导出 Home 组件`

export default class Home extends Component {

   render() {

      return(

         <View style={styles.homeCont}>
            <Text style={styles.homeText}>HOME SCREEN</Text>
            
         </View>
    
     
      )

   }

   

}
相反,做
function Home () {
      return(
         <View style={styles.homeCont}>
            <Text style={styles.homeText}>HOME SCREEN</Text>
         </View>
     )

}

关于javascript - 每个模块只有一个默认导出允许使用 Navbar 在 React Native 上出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65799471/

相关文章:

react-native - 如何在将项目传递给客户端之前保护 native 应用程序中的源代码

wordpress - MAMP直播WP后出现错误

perl - 我应该如何处理 Perl 模块内部或外部的错误?

Javascript - 在此示例中使用 If Else 的最佳实践

javascript - phantomjs 命令行变量

javascript - 在 React Native 中构建应用程序后出现空白屏幕

android - 安装 react-native-device-info 错误 android 后

javascript - 为什么我的 Angular 组件会忽略我的 css 文件?

javascript - 使用 jQuery 获取委托(delegate)事件中被点击的元素

python - 在Python中创建条件