错误:元素类型无效:应为字符串或类/函数,但未定义。反应本机

时间:2020-09-13 19:00:23

标签: reactjs react-native

我知道这是一个常见错误,但是找不到与我的情况相关的答案。

我在一个文件夹中嵌套了两个文件;一个是父功能组件,一个是子功能组件。

父文件正在这样导入和构建

.....
import NavigationIcon from "./NavigationIcon";

const NavigationIcons = () => {
  return (
    <IconContext.Consumer>
      {(icons) => (
        <View>
          {icons.map((icon) => (
       js:12     <NavigationIcon key={icon.id} icon={icon} />
          ))}
        </View>
      )}
    </IconContext.Consumer>
  );
};

export default NavigationIcons;

子文件的结构如下

import React from "react";
import { Pressable, Icon } from "react-native";

function NavigationIcon(props) {
  return (
   js:6 <Pressable onPress={() => console.log("pressed icon ")}>
      <Icon name={props.icon.name} type={props.icon.type} />
    </Pressable>
  );
}

export default NavigationIcon;

这是错误消息:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s%s, 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.

Check your code at NavigationIcon.js:6., 
    in NavigationIcon (at NavigationIcons.js:12)

编辑:我确实尝试将NavigationIcon导入为import {NavigationIcon} from "..."

1 个答案:

答案 0 :(得分:0)

我知道了。我正在使用expo进行应用程序开发,它使用0.62。我正在尝试利用0.63中出现的新组件Pressable