A lightweight React hook for WebSocket communication, forked from react-use-websocket and stripped of SocketIO, EventSource, and connection sharing features. Current stable version 1.1.0 (Feb 2025) targets React 18 and 19, ships TypeScript definitions, and reduces unnecessary re-renders compared to the original. It offers simple URL-based connection, automatic reconnection, and event callbacks (onOpen, onClose, onMessage, onError) while being easier to use performantly.
npm install react-use-websocket-liteNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: connect to a WebSocket, listen for messages, and send a message when the connection opens.
Use dedicated libraries like socket.io-client or eventsource for those protocols.
If you need connection sharing, consider the original react-use-websocket.
Remove these options.
Wrap useWebSocket in a useEffect or use a dynamic import.
Pass `{ connect: false }` if you don't want the connection to start immediately.Run `npm install react-use-websocket-lite`.
Use dynamic import or check for `typeof window !== 'undefined'` before calling the hook.
Change to `import useWebSocket from 'react-use-websocket-lite'`.