2017-04-15 74 views
1

我正在处理React-Native项目,并在尝试实施反应导航时遇到问题。 我也跟着教程,并试图运行项目时,我得到的是说,一个错误:元素类型无效:期望得到字符串/类/函数:对象

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it’s defined in. 

我在网上搜索,包括这个网站,但无法找到任何解决方案。 这是我的代码: index.js:

import React, { Component } from 'react'; 
import { Stack } from './config/Router'; 

class Application extends Component{ 
    render(){ 
    <View> 
     return <Stack />; 
    </View> 
    } 
} 

export default Application; 

这是路由器:

import React from 'react'; 
import { StackNavigator } from 'react-navigation'; 

import Login from '../components/Login'; 
import Home from '../components/Home'; 

export const Stack = StackNavigator({ 
    Login:{ 
    screen: Login 
    }, 
    Home:{ 
    screen: Home, 
    navigationOptions: { 
     title: 'Home' 
    } 
    } 
}); 

,这是index.ios.js:

import { AppRegistry } from 'react-native'; 
import Application from './index' 

AppRegistry.registerComponent('Application',() => Application); 

如何解决错误?提前致谢!

回答

1

它看起来像

class Application extends Component{ 
    render(){ 
    <View> 
     return <Stack />; 
    </View> 
    } 
} 

应该

class Application extends Component{ 
    render(){ 
    return(
     <View> 
     <Stack /> 
     </View> 
    ); 
    } 
} 

你也将需要导入View成分index.js

You likely forgot to export your component from the file it’s defined in.

这几乎总是原因你会一直得到一个无效的元素错误s仔细检查你的进口。

+0

谢谢,但我仍然有同样的错误。 –

+0

@JohnDoah你可能需要在index.js中导入'View'组件 – Emobe

相关问题