React WebSocket is a component-based library for integrating WebSocket connections into React applications. Version 2.1.0 is the latest stable release, with infrequent updates and dependence on community contributions. It provides a simple <Websocket> component with props for URL, message handling, and connection events, and includes built-in reconnection logic. Unlike more complex alternatives, this library offers a minimal, declarative approach but is less actively maintained and lacks advanced features like request/response patterns or subscription management. It requires React 0.14.5+.
npm install react-websocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage: renders a WebSocket component that receives JSON messages and updates state.
Manually JSON.parse(data) inside onMessage.
Ensure parent component unmounts to trigger WebSocket close.
Append parameters to URL or implement custom wrapper.
Set reconnect prop to false and implement custom reconnect if needed.
Consider using alternative libraries like react-use-websocket or socket.io-client.
Run 'npm install react-websocket --save' and ensure React is installed.
Use 'import Websocket from "react-websocket"' (without braces).
Add url prop like <Websocket url='ws://example.com' onMessage={...} />.Ensure server sends valid JSON or wrap parse in try-catch.