A drop-in replacement for the standard WebSocket API in React Native that automatically reconnects when the connection drops. This library wraps the native WebSocket module and provides exponential backoff reconnection logic, configurable intervals, and max attempts. It is API-compatible with the native WebSocket, so you can replace `new WebSocket(url)` with `new ReconnectingWebSocket(url)` without changing event listeners. Current stable version is 2.0.0. Release cadence is low; last release was in 2021. Key differentiators: designed specifically for React Native (no browser dependencies), supports headers (including Cookie and custom Origin), and exposes options like reconnectInterval, maxReconnectInterval, reconnectDecay, timeoutInterval, and maxReconnectAttempts.
npm install react-native-reconnecting-websocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a ReconnectingWebSocket with custom reconnect options and demonstrates basic event handling (open, message, close).
Pass origin under `headers` option: new ReconnectingWebSocket(url, null, { headers: { origin: '...' } })Move the `origin` property into a `headers` object.
Access properties directly (e.g., `e.data`) instead of using `e.target` or other Event properties.
Use a browser-compatible alternative like `reconnecting-websocket` for web apps.
Use alternative authentication methods (e.g., token in URL or message) for iOS.
Run `npm install react-native-reconnecting-websocket` and ensure Metro bundler is restarted.
Change import to `import ReconnectingWebSocket from '...'` (no curly braces).
Only use this package in a React Native app; for web, use a different reconnecting WebSocket library.