简体   繁体   English

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

[英]Error: Element type is invalid: expected a string or a class/function but got undefined. React Native

I know this is a common error but I couldn't find an answer that was relevant for my situation.我知道这是一个常见错误,但我找不到与我的情况相关的答案。

I have two files nested together in a folder;我有两个文件嵌套在一个文件夹中; one is a parent functional component, one is a child functional component.一个是父功能组件,一个是子功能组件。

The parent file is importing and structured like this父文件正在导入并且结构如下

.....
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;

The children file is structured like this子文件的结构是这样的

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;

Here's the error message:这是错误消息:

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)

edit: I did try importing NavigationIcon as import {NavigationIcon} from "..."编辑:我确实尝试将 NavigationIcon import {NavigationIcon} from "..."import {NavigationIcon} from "..."

I figured it out.我想到了。 I'm using expo for my app development and it uses 0.62.我正在使用 expo 进行我的应用程序开发,它使用 0.62。 I was trying to utilize the new component Pressable which came out in 0.63我试图利用 0.63 中出现的新组件Pressable

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:元素类型无效:应为字符串或类/函数,但得到:未定义。 导入错误 - Error: Element type is invalid: expected a string or a class/function but got: undefined. Import error 错误:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。 反应 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. React React Native 错误:元素类型无效:应为字符串或类/函数(对于复合组件)但得到:未定义 - React Native Error: Element type is invalid: expected a string or a class/function (for composite components) but got: undefined React Native 错误:元素类型无效:应为字符串或类/函数,但得到:未定义 - React Native error! Element type is invalid: expected a string or a class/function but got: undefined 元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义。 在 nextjs 中 - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. in nextjs 错误:元素类型无效:应为字符串(用于内置组件)]但得到:未定义。 Nextjs,反应 - Error: Element type is invalid: expected a string (for built-in components) ]but got: undefined. Nextjs, React React native,元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但得到:未定义 - React native, Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined React Native - “元素类型无效:需要字符串或类/函数但未定义” - 导入自定义库? - React Native - “Element type is invalid: expected a string or a class/function but got undefined” - importing custom library? 错误:元素类型无效:应为字符串或类/函数,但得到:未定义 - Error: Element type is invalid: expected a string or a class/function but got: undefined 错误:缩小的 React 错误 #130:元素类型无效:预期为字符串或类/函数,但得到:未定义 - Error: Minified React error #130: Element type is invalid: expected a string or a class/function but got: undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM