Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何在平面列表中使用无限滚动_Reactjs_React Native_Chat_Infinite Scroll_React Native Flatlist - Fatal编程技术网

Reactjs 如何在平面列表中使用无限滚动

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

我想建立聊天应用程序,因为我需要无限滚动加载消息,但有一个问题。当我使用平面列表时,我无法处理更多的时间,因为我必须使用反向平面列表。因为我不能在平面列表中使用onendReach方法。 怎么做

<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])}
/>