how could I cancel fetch operation when component go away (unmount)
example : user open this screen and go back before fetch complete
here is what I have done
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>
);
}
}