Provides a React Native component wrapper around the WebSocket API for managing real-time connections declaratively. Current stable version 1.0.2 (last release in 2019) receives minimal maintenance. Key differentiator: turns WebSocket lifecycle into a React component with props for events (onOpen, onMessage, onClose, onError) and a ref-based send() method. Alternatives like 'react-native-use-websocket' offer hooks-based usage and better maintenance. Requires polyfill for older React Native versions (0.60+) and does not support React Native Web or Expo managed workflow natively.
npm install react-native-websocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up a React Native component with a WebSocket connection, message input, send button, and echo display using WS component and refs.
Consider alternative like 'react-native-use-websocket' or 'WebSocket' from react-native directly.
Use onMessage={(event) => setMessage(event.data)} inside callback.Customize with onReconnect callback or set reconnectAttempts prop.
Use platform-specific code or eject to bare workflow.
Check wsRef.current.readyState === WebSocket.OPEN before sending, or wrap send in onOpen callback.
Call send only after onOpen fires. Use guarded function: if (wsRef.current && wsRef.current.send) wsRef.current.send(data);
Use ws:// for local development (not production), or configure certificate pinning.