首页 > 解决方案 > React Native - 元素类型无效(简单页面视图)

问题描述

我对 React Navigator 有疑问,我对 react native 很陌生,许多解决方案似乎与我的主要问题相去甚远。我已经按照文档所说的那样密切关注。无论如何我仍然会收到此错误:

错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但得到:数字。

检查Splash.

这是我的 App.js

import * as React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import Splash from './pages/Splash';

function HomeScreen() {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Home Screen</Text>
    </View>
  );
}

const Stack = createStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Splash" component={Splash} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default App;

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

快速导入 Splash.js

import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { ILLogo } from '../assets'

const Splash = () => {
    return (
        <View style={styles.page}>
            <ILLogo />
            <Text style={styles.title}>Hooray!!!</Text>
        </View>
    )
}

export default Splash;

const styles = StyleSheet.create({
    page: {
        backgroundColor: '#2BA3DC',
        flex: 1,
        alignItems: 'center',
        flexDirection: 'column',
        justifyContent: 'center'
    },
    title: {
        fontSize: 20,
        fontWeight: '600',
        color: '#fff',
        marginTop: 20
    }
});

我试图通过多种方式导出splash并将其导入,请帮助我

标签: reactjsreact-nativeexpo

解决方案


推荐阅读