Registry / mobile / react-native-cancelable-fetch

react-native-cancelable-fetch

JSON →
library0.1.1jsnpmunverified

A lightweight library for making cancelable HTTP fetch requests in React Native applications (v0.1.1, no recent updates). It wraps the native fetch API and allows cancellation of in-flight requests using a numeric, string, or object tag. This is useful to prevent memory leaks and state updates on unmounted components. Unlike AbortController (not available in older React Native), it provides a simpler tag-based cancellation mechanism. However, the package has not been updated since 2016 and may have compatibility issues with modern React Native versions.

npm install react-native-cancelable-fetch
INSTALL
IMPORT
SIG · REACT-NATIVE-CANCE
R
react-native-cancelable-fetch
mobilejavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import fetch from 'react-native-cancelable-fetch'
const { fetch } = require('react-native-cancelable-fetch')
The module exports a single function as default. CommonJS require returns the function directly, not an object.
fetch.abort
import fetch from 'react-native-cancelable-fetch'; fetch.abort(tag)
import { abort } from 'react-native-cancelable-fetch'
abort is a method on the default export, not a named export.

Demonstrates making a cancelable fetch request and aborting it by tag.

import fetch from 'react-native-cancelable-fetch'; // Make a cancelable request with a tag (number) fetch('https://jsonplaceholder.typicode.com/posts/1', null, 1) .then(res => res.json()) .then(data => console.log(data)) .catch(err => console.error(err)); // Cancel the request with the same tag setTimeout(() => fetch.abort(1), 100);
Debug
Known issues
deprecatedPackage has not been updated since 2016 and may not work with React Native >0.60 or modern JavaScript engines.
fix
Consider using AbortController or a more modern alternative like react-native-abortable-fetch.
affects: >=0.1.1
gotchaThe fetch function overwrites the global fetch if imported incorrectly. Always import as a different name if using native fetch.
fix
Use import cancelableFetch from 'react-native-cancelable-fetch' to avoid name collision.
affects: >=0.0.1
gotchaThe 'init' parameter is not the standard fetch init object; it is passed directly, but handling is minimal.
fix
Ensure the init object matches standard fetch API, but note that some features (like headers) may not work as expected.
affects: >=0.0.1
Errors
Common errors & fixes
Unhandled promise rejection: TypeError: Network request failed
Cancellation triggers a network error, which must be caught in the promise chain.
fix
Always add a .catch() to handle cancellation errors gracefully.
fetch is not a function (after import)
Using default import with React Native's require() incorrectly.
fix
Use import fetch from 'react-native-cancelable-fetch' instead of const fetch = require('react-native-cancelable-fetch').
fetch.abort is not a function
Trying to call abort before importing the default fetch function.
fix
Ensure the import is correct and the module is loaded before calling abort.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
54 hits · last 30 days
node
48
Resources
react-native-cancelable-fetch — npm install react-native-cancelable-fetch · libregistry