Registry /
messaging / react-native-fetch-event-source
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);
},
});
}
Errors
Common errors & fixes
TypeError: (0 , _reactNativeFetchEventSource.fetchEventSource) is not a function
Importing fetchEventSource as default instead of named export.
fixUse `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.
fixRun `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.
fixEnsure you have an onopen handler that receives the response object.
Audit
Dependencies
react-nativerequiredPeer dependency, required for React Native runtime.