1.0.2 • Published 4 years ago

use-fetch-with-timeout v1.0.2

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
4 years ago

useFetchWithTimeout

React Hook - Fetch API Endpoint with Timeouts

Install

npm install use-fetch-with-timeout

Usage

import UsefetchWithTimeout from 'use-fetch-with-timeout'

// UsefetchWithTimeout with default timeout (5000)
const fetch = async () => {
      try {
        const response = await UsefetchWithTimeout(
          'https://someendpoint.org',
        );
        const json = await response.json();
      }
      catch (err) {
        //do something
      }
    };

// UsefetchWithTimeout with custom timeout
const fetch = async () => {
      try {
        const response = await UsefetchWithTimeout(
          'https://someendpoint.org',
          9000
        );
        const json = await response.json();
      }
      catch (err) {
        //do something
      }
    };

License

MIT

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago