1.0.2 • Published 4 years ago
use-fetch-with-timeout v1.0.2
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