创建底部导航时处理本机错误

问题描述 投票:0回答:1

我正在尝试在react native项目中创建底部导航。我收到此错误

不变式违反:元素类型无效:预期的字符串(对于内置组件)或类/函数(对于复合组件),但是未定义。您可能忘记了从定义文件中导出组件,或者可能混淆了默认导入和命名导入

但是我确实导出了所有文件,没有混入任何默认导入或命名导入。

Index.js

import React from 'react';
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import rootReducer from './src/redux/reducers/rootReducer'
import { NavigationContainer } from '@react-navigation/native'

const store = createStore(rootReducer)

const Root = () => (
    <Provider store={store}>
        <NavigationContainer>
            <App />
        </NavigationContainer>
    </Provider>
)

AppRegistry.registerComponent(appName, () => Root);

App.js

import React from 'react';
import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs';
import { MaterialCommunityIcons } from 'react-native-vector-icons';

import Accounts from './src/components/Accounts';
import Categories from './src/components/Categories';
import Transactions from './src/components/Transactions';
import Budget from './src/components/Budget';
import Overview from './src/components/Overview';

const Tab = createMaterialBottomTabNavigator();

export default App = () => {
  return (
    <Tab.Navigator
      initialRouteName="Accounts"
      activeColor="#e91e63"
      labelStyle={{ fontSize: 12 }}
      style={{ backgroundColor: 'tomato' }}
    >
      <Tab.Screen
        name="Accounts"
        component={Accounts}
        options={{
          tabBarLabel: 'Home',
          tabBarIcon: ({ color, size }) => (
            <MaterialCommunityIcons name="home" color={color} size={size} />
          ),
        }}
      />
      <Tab.Screen ... />
<Tab.Screen ... />
    </Tab.Navigator>
  );
}

我的编码有什么错误?我已经经历了先前的问题,但是所有解决方案都将默认值更改为named,反之亦然。

react-native react-navigation
1个回答
0
投票
Adding export default solved my problem

Code :

//Import library to help create component
import React from 'react';
import { AppRegistry } from 'react-native';
import Header from './src/components/header';

//Create a Component
const App = () => (
  <Header />
);

//Export App - This line solved my issue
export default App;

//Render it to the device
AppRegistry.registerComponent('albums', () => App);
//albums is project name that we use while creating RN App
© www.soinside.com 2019 - 2024. All rights reserved.