Javascript 为什么我会得到;元素类型无效";错误?
在Javascript 为什么我会得到;元素类型无效";错误?,javascript,ios,reactjs,debugging,react-native,Javascript,Ios,Reactjs,Debugging,React Native,在错误中我进入的iOS模拟器对我来说没有意义。我觉得我的Home.js组件很好。我不明白我怎么会犯这个错误。我已经清楚地导出了组件。我怎样才能消除这个错误 这里是Home.js: import React from 'react'; import Container from 'native-base'; import {MapContainer} from "../../../components/MapContainer/index"; class Home extends React.C
错误中
我进入的iOS
模拟器对我来说没有意义。我觉得我的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;
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>
);
}
下面是错误
:
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'.
你们这里有两个出口
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;
从“React”导入React;
从“本机基础”导入视图;
从“react native maps”导入MapView;
从“/MapContainerStyles”导入样式;
//从下一行删除导出
导出常量映射容器=({region})=>{
返回(
);
}
导出默认映射容器;
这里有两个导出
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;
从“React”导入React;
从“本机基础”导入视图;
从“react native maps”导入MapView;
从“/MapContainerStyles”导入样式;
//从下一行删除导出
导出常量映射容器=({region})=>{
返回(
);
}
导出默认映射容器;
您的映射容器中有2个导出
在顶部有一个export const MapContainer
你在底部有一个<代码>导出默认映射容器代码>
现在您需要删除一个,但保留的一个将决定以后如何导入它
如果保留默认导出,则按此方式导入
从“../../../components/MapContainer/index”导入MapContainer代码>
如果保留非默认导出,则会像这样导入
从“../../../components/MapContainer/index”导入{MapContainer}”代码>您的映射容器中有2个导出
在顶部有一个export const MapContainer
你在底部有一个<代码>导出默认映射容器代码>
现在您需要删除一个,但保留的一个将决定以后如何导入它
如果保留默认导出,则按此方式导入
从“../../../components/MapContainer/index”导入MapContainer代码>
如果保留非默认导出,则会像这样导入
从“../../../components/MapContainer/index”导入{MapContainer}”代码>啊,我明白了。非常感谢。我完全理解这个概念。但每当我试图在代码中实现这一点时。由于某些原因,我仍然收到相同的错误。现在在我的原始帖子中发布了它不确定。我只是想重现你的场景,对我来说效果很好。对不起,我明白了。非常感谢。我完全理解这个概念。但每当我试图在代码中实现这一点时。由于某些原因,我仍然收到相同的错误。现在在我的原始帖子中发布了它不确定。我只是想重现你的场景,对我来说效果很好。很抱歉