React Native Fetch with Timeout
Personal usage only. No further support.
Fetch with timeout for React Native.
Installation
npm install -S @gluons/react-native-fetch-with-timeout
or
yarn add @gluons/react-native-fetch-with-timeout
Usage
import { Alert } from 'react-native';
import fetchWithTimeout from '@gluons/react-native-fetch-with-timeout';
(async () => {
try {
const res = await fetchWithTimeout(
'https://<request-url>',
{},
{
timeout: 5000 // 5 seconds
}
)
} catch (err) {
// Thrown "Request Timeout" error after 5 seconds
Alert.alert('Error', err.toString());
}
})();