You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用React Native Material的AppBar时遇Element type is invalid错误求助

问题分析与解决方案

这个错误的核心原因是**Icon组件的导入方式错误**,react-native-vector-icons的每个图标库(比如Entypo)都是默认导出Icon组件,而非命名导出。你的代码里用了{Icon}的命名导入,导致实际导入的是undefined,进而引发元素类型无效的错误。

修正步骤:

  1. 调整Icon的导入语句,改为默认导入:
import Icon from 'react-native-vector-icons/Entypo';
  1. 修正后的完整代码:
import { AppBar, IconButton } from '@react-native-material/core';
import Icon from 'react-native-vector-icons/Entypo';

<AppBar
  title="Title"
  leading={props => (
    <IconButton
      icon={iconProps => <Icon name="menu" {...iconProps} />}
      {...props}
    />
  )}
/>

额外检查点:

  • 确认已经安装react-native-vector-icons依赖:npm install react-native-vector-icons 或 yarn add react-native-vector-icons
  • 如果你使用的是React Native 0.60以下版本,需要手动执行链接:react-native link react-native-vector-icons(新版本已支持自动链接,可跳过)

内容的提问来源于stack exchange,提问作者Leo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 19:55:35