Reputation: 3052
This my code(used to fetch data).
loadApi() {
this.setState({isListLoaded : true})
return fetch('http://www.androidbegin.com/tutorial/jsonparsetutorial.txt')
.then((response) => response.json())
.then((responseJson) => {
this.setState({listView : responseJson.worldpopulation})
this.setState({isListLoaded : false})
ToastAndroid.show('A pikachu appeared nearby !', ToastAndroid.SHORT);
})
.catch((error) => {
console.error(error);
});
}
How can i set a timeout to this specific syntax ?.Please share the code part if you have any.
Upvotes: 1
Views: 4013
Reputation: 35569
There is no standard way till now according to this github thread.
However there is one solution, use whatwg-fetch-timeout
sample code :
return fetch('/path', {timeout: 500}).then(function() {
// successful fetch
}).catch(function(error) {
// network request failed / timeout
})
Upvotes: 1