
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
react-native-fetch-polyfill
Advanced tools
A polyfill for React Native's whatwg-fetch
's mirror.
This adds support for timeout
as one of the fetch
options.
import fetch from 'react-native-fetch-polyfill';
fetch(url, {timeout: 30 * 1000})
.then(response => {
// a successful response
})
.catch(error => {
// an error when the request fails, such as during a timeout
})
React Native's XMLHttpRequest
interface exposes a timeout property sent to the RCTNetworking
module, as well as an abort method. fetch
does not expose access to this by default, this polyfill allows specifying a timeout
within the options.
This value attached to NSMutableURLRequest
, where the native networking layer will enforce the timeout rule.
The result of the timeout being reached will result in a promise rejected with a `TypeError('Network rqeuest failed').
Fetch is a networking abstraction above XMLHttpRequest
. It reflects the WHATWG fetch specification and can be found in whatwg/fetch. It is the networking library used in React Native.
Fetch has two challenges:
timeout
(https://github.com/facebook/react-native/issues/2394, https://github.com/facebook/react-native/issues/2556, https://github.com/whatwg/fetch/issues/20, https://github.com/github/fetch/issues/175)Why are these not supported? As a fetch
maintainer points out in https://github.com/github/fetch/pull/68#issuecomment-70103306, the spec does not describe a standard for this behavior.
The polyfill picks out specific pieces of whatwg/fetch required to apply the patch.
The tagged version of the polyfill corresponds to the version of fetch
that it patches.
When new versions of fetch
are released, the polyfill will be updated and tagged.
FAQs
A polyfill for React Native's fetch client
The npm package react-native-fetch-polyfill receives a total of 1,042 weekly downloads. As such, react-native-fetch-polyfill popularity was classified as popular.
We found that react-native-fetch-polyfill demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.