0
我怎麼能取消的時候分量離開(卸載)中止取時組件卸載
例如讀取操作:用戶打開此屏幕和前回去取完整
這裏是我做了什麼
export default class LecturesScreen extends React.Component
{
constructor(props){
super(props);
this.state = {lectures : [] , loadingNow : true}
}
componentDidMount(){
this.loadLectures();
}
loadLectures =() =>{
fetch(Link.api.lecture.newest , {method : 'POST'})
.then((response) =>
{
this.setState({lectures : response , loadingNow: false});
})
.catch((error)=>
{
console.log(error);
});
};
render(){
return (
<View>
<List dataArray={this.state.lectures}
renderRow={(item) => <LectureListItem title={item.Title}/>}
/>
</View>
);
}
}
我認爲這將不會中止'獲取'功能 – Ali
看看這篇文章。 https://discuss.reactjs.org/t/cancel-async-fetch-on-unmount/3272 – Etherealm
感謝您的重播 – Ali