@gluons/react-native-fetch-with-timeout

Fetch with timeout for React Native.

Usage no npm install needed!

<script type="module">
  import gluonsReactNativeFetchWithTimeout from 'https://cdn.skypack.dev/@gluons/react-native-fetch-with-timeout';
</script>

README

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());
    }
})();