[英]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.