简体   繁体   English

Algolia和React Native FlatList ListHeaderComponent

[英]Algolia and React Native FlatList ListHeaderComponent

I you put an Algolia connected component in a header of a FlatList it's as if it enters an infinite loop of queries. 我将Algolia连接的组件放在FlatList的标头中,就好像它进入了无限查询循环。 The connectInfiniteHits runs constantly. connectInfiniteHits持续运行。

This is really annoying if you like to put some simple filters in the headers of a list of hits. 如果您想在匹配列表的标题中放置一些简单的过滤器,这真是令人讨厌。

My setup is like this: 我的设置是这样的:

I have a FlatList that is wrapped by the connectInfiniteHits HOC. 我有一个由connectInfiniteHits HOC包装的FlatList。 The ListHeaderComponent contains a component this is wrapped by the connectRefinementList HOC. ListHeaderComponent包含一个由connectRefinementList HOC包装的组件。 The same problem occurs with a connectSearchBox HOC. connectSearchBox HOC发生相同的问题。

Has anyone seen this and found a solution? 有没有人看到这并找到解决方案?

I manage to make it work with those lines: 我设法使其与这些行一起工作:

const RefinementList = connectRefinementList(({ items, refine }) => (
  <View>
    {items.map(item => (
      <TouchableOpacity key={item.label} onPress={() => refine(item.value)}>
        <Text style={{ fontWeight: item.isRefined ? '600' : 'normal' }}>
          {item.label}
        </Text>
      </TouchableOpacity>
    ))}
  </View>
));

const InfiniteHits = connectInfiniteHits(({ hits, hasMore, refine }) => (
  <FlatList
    data={hits}
    keyExtractor={item => item.objectID}
    onEndReached={() => hasMore && refine()}
    ListHeaderComponent={<RefinementList attribute="brand" />}
    renderItem={({ item }) => (
      <View>
        <Text>{JSON.stringify(item).slice(0, 100)}</Text>
      </View>
    )}
  />
));

Note that I'm not using the function version which indeed breaks. 请注意,我没有使用确实中断的功能版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native Flatlist ListHeaderComponent 不起作用 - React Native Flatlist ListHeaderComponent Doesn't Work React Native Flatlist ListHeaderComponent 未在 state 更改上呈现 - React Native Flatlist ListHeaderComponent is not rendered on state change 如何使 ListHeaderComponent 的一部分粘在 React Native FlatList 上 - How to make a part of ListHeaderComponent sticky on React Native FlatList 你如何让 React Native FlatList 的 ListHeaderComponent 变得有粘性? - How do you make the ListHeaderComponent of a React Native FlatList sticky? 如何在 React Native 平面列表中滚动期间隐藏 ListHeaderComponent - How do I hide the ListHeaderComponent during scroll in a React Native flatlist React Native Android 关注 Flatlist 的粘性 ListHeaderComponent 中的 TextInput 使列表滚动 position 对齐到 y = 0 - React Native Android focus on TextInput inside Flatlist's sticky ListHeaderComponent makes list scroll position snap to y = 0 在 numColumns 中包含 ListHeaderComponent - React-Native - Include ListHeaderComponent in numColumns - React-Native 如何滚动到 Flatlist ListHeaderComponent 顶部? - How to scrollTo Flatlist ListHeaderComponent top? FlatList、Props ListHeaderComponent 和动态 flatlist 数据 - FlatList, Props ListHeaderComponent and Dynamic flatlist data React Native onEndReached Flatlist - React Native onEndReached Flatlist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM