Registry / messaging / react-native-fetch-event-source

react-native-fetch-event-source

JSON →
library1.0.1jsnpmunverified

A library for consuming Server-Sent Events (SSE) in React Native using the Fetch API. Version 1.0.1, adapted from @microsoft/fetch-event-source. Provides full control over request method, headers, body, and retry logic, unlike the native EventSource API. Supports automatic reconnection, page visibility optimization, and is fully compatible with the Event Stream format. Ships TypeScript types. Requires React Native >=0.74.0.

npm install react-native-fetch-event-source
INSTALL
IMPORT
SIG · REACT-NATIVE-FETCH
R
react-native-fetch-event-source
messagingjavascriptv1.0.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.

fetchEventSource
import { fetchEventSource } from 'react-native-fetch-event-source'
import fetchEventSource from 'react-native-fetch-event-source'
The library exports fetchEventSource as a named export, not a default export.
EventStreamContentType
import { EventStreamContentType } from 'react-native-fetch-event-source'
Useful for checking response content type in onopen handler.
FetchEventSourceInit
import { FetchEventSourceInit } from 'react-native-fetch-event-source'
Type for the options parameter of fetchEventSource. Available when using TypeScript.

Shows how to use fetchEventSource with custom method, headers, body, abort signal, and event handlers.

import { fetchEventSource } from 'react-native-fetch-event-source'; async function startSSE() { const ctrl = new AbortController(); await fetchEventSource('https://example.com/events', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ topic: 'updates' }), signal: ctrl.signal, onopen: async (response) => { if (response.ok) { console.log('Connection opened'); } else { throw new Error('Failed to connect'); } }, onmessage: (event) => { console.log('Received:', event.data); }, onclose: () => { console.log('Connection closed'); }, onerror: (err) => { console.error('Error:', err); }, }); }
Debug
Known issues
breakingRequires React Native >=0.74.0; older versions not supported.
fix
Upgrade React Native to 0.74.0 or later.
affects: <0.74.0
gotchafetchEventSource returns a Promise<void> that resolves when the connection is closed by the server or aborted. Use AbortController to cancel.
fix
Always provide an AbortController signal to properly manage connection lifecycle.
affects: >=1.0.0
deprecatedThe onclose callback is called when the connection terminates normally. Not called on error or abort. Ensure you handle both onclose and onerror.
fix
Use onclose only for clean disconnects; handle error/abort separately.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , _reactNativeFetchEventSource.fetchEventSource) is not a function
Importing fetchEventSource as default instead of named export.
fix
Use `import { fetchEventSource } from 'react-native-fetch-event-source'`
Cannot find module 'react-native-fetch-event-source'
Package not installed or React Native version too old.
fix
Run `npm install react-native-fetch-event-source` and ensure React Native >=0.74.0.
Unhandled Promise Rejection: Error: Cannot read properties of undefined (reading 'ok')
Missing onopen handler or response is undefined.
fix
Ensure you have an onopen handler that receives the response object.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
react-nativerequiredPeer dependency, required for React Native runtime.
Agent activity
16 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
react-native-fetch-event-source — npm install react-native-fetch-event-source · libregistry