react-native - React Native 声称我没有正确导入/导出
问题描述
我不明白为什么会收到以下错误消息,因为我相信我已经正确使用了默认导出和导入:
Invariant Violation: 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, or you might have mixed up default and named imports.
我有两个组件类:Main 和 Menu。
在 MainComponent.js 中:
import React, { Component } from 'react';
import Menu from './MenuComponent';
import { DISHES } from '../shared/dishes';
class Main extends Component {
constructor(props) {
super(props);
this.state = {
dishes: DISHES
}
}
render() {
return(
<Menu dishes={this.state.dishes} />
);
}
}
export default Main;
在 MenuComponent.js 中:
import React, {Component} from 'react';
import {View, Flatlist} from 'react-native';
import { ListItem } from 'react-native-elements';
function Menu(props) {
const renderMenuItem = ({item, index}) => {
return(
<ListItem
key={index}
title={item.name}
subtitle={item.description}
hideCheveron={true}
leftAvatar={{source: require('./images/uthappizza.png')}}
/>
);
}
return(
<Flatlist
data={props.dishes}
renderItem={renderMenuItem}
keyExtractor={item => item.id.toString()}
/>
);
}
export default Menu;
解决方案
The issue might be with the import of FlatList
from react-native
(note the capital "L").
推荐阅读
- left-join - 在语句之间使用左连接访问 SQL 会导致错误“在查询表达式中没有 And 的运算符之间”
- java - 尝试使用 jdbc URL 连接到远程 IP 时 MySQL 8 上的 javax.naming.NoInitialContextException
- python-3.x - “selenium.common.exceptions.TimeoutException:消息:”错误
- javascript - Webpack:导出默认类未在 index.html 上定义
- debugging - 我的机器人在设置我的 webhook 后没有回复?
- react-native - KeyboardAvoidingView 在我的应用程序上无法正常工作
- python - 如何在没有 Anaconda 的 Mac OS(Big Sur、Catalina、Mojave)上安装 TensorFlow 2.X?
- typescript - 不是另一个 TS2511:无法创建抽象类的实例
- r - 识别R中不对称矩阵中对角线上方或下方的所有单元格
- python - 如何在模块中调用整个类?