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

使用StackNavigator时遇this.props.header不是函数错误求助

Fixing "Error: this.props.header is not a function" in PassportScreen with react-native-accordion

Hey there, let's break down and fix this error you're hitting. The root cause here is almost certainly tied to how you're using the @ercpereda/react-native-accordion component in your PassportScreen—this component expects the header prop to be a function that returns a React element, but you're likely passing a raw JSX element or non-function value instead.

Here's how to resolve it step by step:

1. Correct the Accordion Component Usage

First, double-check where you're rendering the Accordion component. The header prop must be a function, not direct JSX.

Wrong (causes the error):

<Accordion
  header={<Text>My Accordion Header</Text>}
  content={<View>...</View>}
/>

Correct:

<Accordion
  // header is a function that returns your desired header component
  header={() => <Text>My Accordion Header</Text>}
  // content should also be a function for consistency
  content={() => <View>...</View>}
/>

2. Adjust Your renderItem Function

Since you're using a FlatList with ListItem, you probably have the Accordion inside your renderItem method. Update it to pass a function to the header prop, like this:

renderItem = ({ item }) => {
  return (
    <Accordion
      header={() => (
        <ListItem
          title={item.title}
          subtitle={item.subtitle}
          chevron // keeps the expand/collapse indicator
        />
      )}
      content={() => (
        <View style={styles.accordionContent}>
          <Text>{item.details}</Text>
          {/* Add any other content you want to show when expanded */}
        </View>
      )}
    />
  );
};

3. Additional Checks

  • If you're passing dynamic data to the Accordion, make sure each item's header value is wrapped in a function. Avoid passing static JSX directly—always wrap it in () => {}.
  • Verify there's no conflict with other header props elsewhere in your code (like custom navigation headers). Your current navigationOptions only sets a title, so this shouldn't be an issue here.

Once you adjust the Accordion's header prop to be a function, the error should disappear, and your accordions will render correctly in the PassportScreen.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 09:16:07