我开始对本机做出反应,如果我的问题很愚蠢,请对不起。
我有一个简单的FlatList,可以通过onEndReached
和onEndReachedThreshold
进行定义。
<FlatList data={this.state.dataTest}
keyExtractor={(item, index) => index.toString()}
renderItem={({item}) => <FilmItems film={item}/>}
onEndReachedThreshold={0.1}
onEndReached={(e) => {
if (e.distanceFromEnd < 0) return;
this._loadData()
}}
/>
MyLoadData方法 一个简单的api调用
_loadDataTest() {
this.setState({ isLoading: true })
if (this.searchedText.length > 0 && this.page <= this.totalPages) {
getDataCallAPiTest(this.searchedText, this.page+1).then( data => {
console.log('data', data )
this.page = data.page
this.totalPages = data.total_pages
this.setState({
dataTest: this.state.dataTest.concat(data.results),
isLoading: false
})
})
}
}
如果我滚动了5次,那么5次api调用,我出错了
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
如果我的列表包含更多80个对象,则会出现此错误 一张地图
adult: false
backdrop_path: "/4GlSMUpzSd3cliYGFJVziSDX53S.jpg"
genre_ids: (2) [12, 14]
id: 671
original_language: "en"
original_title: "Harry Potter and the Philosopher's Stone"
overview: "Orphelin, Harry Potter a été recueilli en bas âge par sa tante Pétunia et son oncle Vernon, deux abominables créatures qui, depuis dix ans, prennent un malin plaisir à l’humilier, le houspiller et le malmemer. Contraint de se nourrir de restes et de dormir dans un placard infesté d’araignées, le malheureux est en butte à l’hostilité de son cousin Dudley, obèse imbécile qui ne manque pas une occasion de le rouer de coups. L’année de ses 11 ans, Harry ne s’attend pas à recevoir de cadeaux, pourtant cette année là, une lettre mystérieuse va lui parvenir qui va changer son existence..."
popularity: 135.056
poster_path: "/fbxQ44VRdM2PVzHSNajUseUteem.jpg"
release_date: "2001-11-16"
title: "Harry Potter à l'école des sorciers"
video: false
vote_average: 7.9
vote_count: 18622
我不知道为什么,所以你可以帮助我。 谢谢