Javascript 组件赢得';我不认识它';它正在出口
我遇到了一个非常奇怪的错误。我觉得我已经以正常和常规的方式导出了Javascript 组件赢得';我不认识它';它正在出口,javascript,ios,reactjs,debugging,react-native,Javascript,Ios,Reactjs,Debugging,React Native,我遇到了一个非常奇怪的错误。我觉得我已经以正常和常规的方式导出了Home组件。下面,我发布了我认为与纠正此错误相关的.js文件。尽管如此,在我的iOS模拟器中,我仍然收到一个错误,上面写着: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forg
Home
组件。下面,我发布了我认为与纠正此错误相关的.js
文件。尽管如此,在我的iOS
模拟器中,我仍然收到一个错误,上面写着:
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'.
这里是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 styles from './MapContainerStyles';
import * as MapView from "react-native-maps/lib/components/ProviderConstants";
const MapContainer = ({region}) => {
return(
<View style={styles.container}>
<MapView
provider={MapView.PROVIDER_GOOGLE}
style={styles.map}
region={region}
>
</MapView>
</View>
);
}
export default MapContainer;
问题不在于导出
主页
。我们知道这是因为正在调用Home
的render
从错误中可以看出,Container
或MapContainer
未正确导入。我怀疑是容器
是命名的导出,因此需要使用命名的导入:
import { Container } from 'native-base';
更新:是的,下面是一个来自
好的,我做到了。但是现在我得到了同样的错误,那就是检查
MapContainer
的渲染方法,而不是Home.js
@hop38:在MapContainer
code.Hmm中的另一个导入中,也会出现同样的错误,我明白你的意思了。最初,我想像这样导入MapContainer
:从“/MapContainer”导入MapContainer
,但它不允许我这样做。现在导入它的方式是WebStorm
IDE给我的建议。我有一种感觉,这与我遇到的错误有关。@hop38:好吧,它不会是MapContainer
导入(就像它不是Home
导入),因为MapContainer
的渲染正在被调用(就像Home
被调用一样)。如上所述,在MapContainer
代码中查找类似的import
错误。我相信这就是我导入MapView
的方式。起初,我尝试从“react native maps
导入地图视图,但在WebStorm中,我得到一个错误,即导入模块中未声明默认导出。在我的原始帖子中导入MapView
的方式再次是WebStorm的建议。
import {Container, Content, Text} from 'native-base';