Reactjs 如何在平面列表中使用无限滚动
我想建立聊天应用程序,因为我需要无限滚动加载消息,但有一个问题。当我使用平面列表时,我无法处理更多的时间,因为我必须使用反向平面列表。因为我不能在平面列表中使用onendReach方法。 怎么做Reactjs 如何在平面列表中使用无限滚动,reactjs,react-native,chat,infinite-scroll,react-native-flatlist,Reactjs,React Native,Chat,Infinite Scroll,React Native Flatlist,我想建立聊天应用程序,因为我需要无限滚动加载消息,但有一个问题。当我使用平面列表时,我无法处理更多的时间,因为我必须使用反向平面列表。因为我不能在平面列表中使用onendReach方法。 怎么做 <FlatList data={data.chatDetail.edges} keyExtractor={(item, index)=>String(index)} renderItem={({item})=>{ return(<TopicMai
<FlatList
data={data.chatDetail.edges}
keyExtractor={(item, index)=>String(index)}
renderItem={({item})=>{
return(<TopicMain style={styles.topicMain} data={item}/>)
}}
inverted={true}
/>
字符串(索引)}
renderItem={({item})=>{
返回()
}}
反向={true}
/>
我目前正在使用它
// get before topreach 5.th item
const thresouldVal = data.chatDetail.edges.slice(-5)
const reachIds = thresouldVal.map(val => val._id)
const handleLoadMore = useCallback((lastViewableItem) => {
// check is top reach
const isTopReach = reachIds.includes(lastViewableItem.item._id)
if (isTopReach) {
// fetchMore
}
}, [reachIds],
)
扁平列表
<FlatList
data={data.chatDetail.edges}
keyExtractor={(item, index) => String(index)}
renderItem={({ item }) => {
return (<TopicMain style={styles.topicMain} data={item} />)}}
inverted={true}
onViewableItemsChanged={({ viewableItems, changed }) =>{handleLoadMore(viewableItems.slice(-1)[0]) }}
/>
字符串(索引)}
renderItem={({item})=>{
返回()}
反向={true}
onViewableItemsChanged={({viewableItems,changed})=>{handleLoadMore(viewableItems.slice(-1)[0])}
/>