0

没有重载匹配此调用。重载 1 of 2,'(props: Readonly<SectionListProps>): SectionList',给出了以下错误。'{ children: any[]; 类型中缺少属性 'sections' }' 但在类型 'Readonly<SectionListProps>' 中是必需的。Overload 2 of 2, '(props: SectionListProps, context?: any): SectionList',给出了以下错误。'{ children: any[]; 类型中缺少属性 'sections' }' 但在类型 'Readonly<SectionListProps>' 中是必需的。

    <SafeAreaView>
    <SectionList>
      ListHeaderComponent={() => (
        <>
        <BarApresentation bar={bar}/>
        <CategoryList/>
        <HightlightList/>
        </>
      )}
      sections={organizedDishes}
      keyExtractor={(item: { id: number; }) => item.id}
      renderItem={({ item }) => (
        <View>
          <Text>
            {item.name}
          </Text>
        </View>
      )}
      renderSectionHeader={({ sections }) => (
        <Text>{Title}</Text>
      )}
    </SectionList>
    
    </SafeAreaView>```
4

1 回答 1

1

您将道具作为孩子传递,而不是SectionList. 尝试以下操作:

    <SafeAreaView>
    <SectionList
      ListHeaderComponent={() => (
        <>
        <BarApresentation bar={bar}/>
        <CategoryList/>
        <HightlightList/>
        </>
      )}
      sections={organizedDishes}
      keyExtractor={(item: { id: number; }) => item.id}
      renderItem={({ item }) => (
        <View>
          <Text>
            {item.name}
          </Text>
        </View>
      )}
      renderSectionHeader={({ sections }) => (
        <Text>{Title}</Text>
      )}
    />
    
    </SafeAreaView>
于 2020-10-08T03:02:03.110 回答