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

React Native导航栏添加筛选图标报错:object is not a function

解决React Native导航头部图标报错“object is not a function”
  • 问题根源:headerLeft属性要求传入返回React元素的函数,你直接传入了JSX元素,导航框架会尝试调用它,自然会报“object is not a function”。

  • 修正后的代码:

import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons';

// ...

<Stack.Screen
  name="Address"
  component={Address}
  options={{
    headerLeft: () => (
      <MaterialCommunityIcons 
        name="filter" 
        size={24} 
        color="black" 
        style={{ marginLeft: 16 }} 
      />
    )
  }}
/>
  • 额外说明:
    • 如果需要给图标加点击事件,直接在函数里给图标绑定onPress即可,比如:
      headerLeft: () => (
        <MaterialCommunityIcons 
          name="filter" 
          size={24} 
          color="black" 
          style={{ marginLeft: 16 }}
          onPress={() => { /* 这里写筛选逻辑 */ }}
        />
      )
      
    • 记得先确保已经安装了图标库(比如@expo/vector-icons或者react-native-vector-icons),并正确导入组件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 08:52:01