[英]React Native Element Type is Invalid. Check Render Method
I've looked around and most of these issues are a result if importing or exporting incorrectly but I've checked around my app and I'm not sure what I'm exporting/importing incorrectly. 我环顾四周,如果导入或导出不正确,大多数问题都是结果,但我已经检查了我的应用程序,我不确定我导出/导入的错误。 This is the exact error I'm getting.
这是我得到的确切错误。
React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
React.createElement:type无效 - 期望一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:object。 You likely forgot to export your component from the file it's defined in. Check the render method of
FooterTabs
.您可能忘记从其定义的文件中导出组件。检查
FooterTabs
的render方法。
Not sure what it means by render method. 不确定render方法的含义。 The component doesn't have a render method.
该组件没有render方法。 Anyways...
无论如何...
So FooterTabs
is just me rendering some footer tabs 所以
FooterTabs
只是我渲染一些页脚选项卡
import React, { PropTypes } from 'react'
import { View, Text } from 'react-native'
import { Tabs, Tab, Icon } from 'react-native-elements'
import { HomeContainer, TrackLibraryContainer } from '~/containers'
import { NimbusCamera } from '~/components'
export default function FooterTabs (props) {
console.log(props)
FooterTabs.propTypes = {
navigator: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
activeFooterTab: PropTypes.string.isRequired,
setFooterTab: PropTypes.func.isRequired,
}
return (
<Tabs>
<Tab
selected={props.activeFooterTab === "home"}
titleStyle={{fontWeight: 'bold', fontSize: 10}}
selectedTitleStyle={{marginTop: -1, marginBottom: 6}}
title="Home"
onPress={(tab) => props.dispatch(props.setFooterTab("home"))}
renderIcon={() => <Icon containerStyle={{justifyContent: 'center', alignItems: 'center', marginTop: 12}} color={'#5e6977'} type="ionicon" name='ios-home-outline' size={33} />}>
<HomeContainer navigator={navigator}/>
</Tab>
<Tab
selected={props.activeFooterTab === "camera"}
titleStyle={{fontWeight: 'bold', fontSize: 10}}
selectedTitleStyle={{marginTop: -1, marginBottom: 6}}
title="Record Preview"
onPress={(tab) => props.dispatch(props.setFooterTab("camera"))}
renderIcon={() => <Icon containerStyle={{justifyContent: 'center', alignItems: 'center', marginTop: 12}} color={'#5e6977'} type="ionicon" name='ios-camera-outline' size={33} />}>
<NimbusCamera navigator={navigator}/>
</Tab>
<Tab
titleStyle={{fontWeight: 'bold', fontSize: 10}}
selectedTitleStyle={{marginTop: -1, marginBottom: 6}}
title="Available Streams"
onPress={(tab) => props.dispatch(props.setFooterTab("library"))}
renderIcon={() => <Icon containerStyle={{justifyContent: 'center', alignItems: 'center', marginTop: 12}} color={'#5e6977'} type="ionicon" name='ios-musical-notes-outline' size={33} />}>
<TrackLibraryContainer navigator={navigator}/>
</Tab>
</Tabs>
)
}
I then export it in app/components/index.js
like export { default as FooterTabs } from './FooterTabs/FooterTabs'
然后我将它导出到
app/components/index.js
例如export { default as FooterTabs } from './FooterTabs/FooterTabs'
All other components that are imported are exported the same way. 导入的所有其他组件以相同的方式导出。
I probably just need another set of eyes here. 我可能只需要另一组眼睛。 Let me know if you need to see any other files code.
如果您需要查看任何其他文件代码,请告诉我。
Thanks! 谢谢!
I believe that navigator
is undefined, causing errors when rendering the child components. 我相信
navigator
是未定义的,在渲染子组件时会导致错误。 In this case, navigator={navigator}
needs to be changed to navigator={props.navigator}
in your HomeContainer
, NimbusCamera
, and TrackerLibraryContainer
components. 在这种情况下,需要将
navigator={navigator}
更改为HomeContainer
, NimbusCamera
和TrackerLibraryContainer
组件中的navigator={props.navigator}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.