@yogaraj-saravanan/react-websocket-hooks
v1.0.1
Published
Lightweight React hooks for managing WebSocket connections.
Maintainers
Readme
@yogaraj-saravanan/react-websocket-hooks
A lightweight, customizable React hook to simplify WebSocket integration in your React apps. Easily send and receive messages using this modern and reusable hook.
✨ Features
- 🔌 Simple WebSocket connection with React Hooks
- 📥 Auto-reconnect support
- 📤 Message sending and receiving
- ⚛️ Fully compatible with modern React
- 🧪 Jest test cases included
📦 Installation
npm install @yogaraj-saravanan/react-websocket-hooksor
yarn add @yogaraj-saravanan/react-websocket-hooks🚀 Usage
import { useWebSocket } from "@yogaraj-saravanan/react-websocket-hooks";
const MyComponent = () => {
const { sendMessage } = useWebSocket("ws://localhost:8080");
const handleClick = () => {
sendMessage("Hello WebSocket!");
};
return <button onClick={handleClick}>Send</button>;
};🧪 Run Tests
npm run test🔨 Build
npm run build📄 License
MIT
