@gluons/react-native-fetch-with-timeout
Version:
Fetch with timeout for React Native.
40 lines (30 loc) • 786 B
Markdown
> Personal usage only. No further support.
[](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) with timeout for [React Native](https://reactnative.dev/).
```bash
npm install -S @gluons/react-native-fetch-with-timeout
```
or
```bash
yarn add @gluons/react-native-fetch-with-timeout
```
```js
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());
}
})();
```