[英]Why am I getting “Element type is invalid” error?
In the error
I'm getting in my iOS
simulator doesn't make sense to me. error
是我进入iOS
模拟器对我来说没有意义。 My Home.js
component seems fine to me. 我的
Home.js
组件对我来说似乎很好。 I can't understand how I'm getting this error. 我不明白如何收到此错误。 I've clearly exported the component.
我显然已经导出了该组件。 How can I get rid of this error?
如何摆脱这个错误?
Here's Home.js
: 这是
Home.js
:
import React from 'react';
import Container from 'native-base';
import {MapContainer} from "../../../components/MapContainer/index";
class Home extends React.Component {
componentDidMount() {
this.props.setName();
}
render() {
const region = {
latitude: 3.146642,
longitude: 101.695845,
latitudeDelta: 0.8922,
longitudeDelta: 0.0421
}
return(
<Container>
<MapContainer region={region}/>
</Container>
);
}
}
export default Home;
Here's index.js
: 这是
index.js
:
import React from 'react';
import View from 'native-base';
import MapView from 'react-native-maps';
import styles from './MapContainerStyles';
export const MapContainer = ({region}) => {
return(
<View style={styles.container}>
<MapView
provider={MapView.PROVIDER_GOOGLE}
style={styles.map}
region={region}
>
</MapView>
</View>
);
}
Here's the error
: 这是
error
:
Element type is invalid: expected a string (for built-in components) or
a class/function (for composite components) but got: undefined. You
likely forgot to export your component from the file it's defined in.
Check the render method of 'Home'.
you have two exports here 你这里有两个出口
import React from 'react';
import View from 'native-base';
import MapView from 'react-native-maps';
import styles from './MapContainerStyles';
//delete export from the next line
export const MapContainer = ({region}) => {
return(
<View style={styles.container}>
<MapView
provider={MapView.PROVIDER_GOOGLE}
style={styles.map}
region={region}
>
</MapView>
</View>
);
}
export default MapContainer;
You have 2 exports in your MapContainer
. 您的
MapContainer
有2个导出。
You have this one at the top export const MapContainer
您在顶部
export const MapContainer
拥有一个
and you have this one at the bottom. 并且您在底部有这个。
export default MapContainer;
Now you need to get rid of one, but the one you keep will determine how you import it later. 现在您需要删除其中一个,但是保留的一个将决定以后如何导入它。
If you keep the default export you then import like so 如果保留默认导出,则可以像这样导入
import MapContainer from "../../../components/MapContainer/index";
If you keep the non default export you will import like so 如果保留非默认导出,则将这样导入
import {MapContainer} from "../../../components/MapContainer/index";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.