[英]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.