{"_id":"react-use-websocket-lite","_rev":"4-3fbf8c028129abdc76728238bfb84a40","name":"react-use-websocket-lite","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.0":{"name":"react-use-websocket-lite","version":"1.0.0","keywords":["react","react-hooks","websocket","websockets"],"license":"MIT","_id":"react-use-websocket-lite@1.0.0","maintainers":[{"name":"michaelboyles","email":"michaelboyles@hotmail.co.uk"}],"contributors":[{"name":"Michael Boyles","email":"michael@boyl.es"},{"url":"robtaussig.com","name":"Robert Taussig","email":"robert.taussig@gmail.com"}],"homepage":"https://github.com/michaelboyles/react-use-websocket-lite#readme","bugs":{"url":"https://github.com/michaelboyles/react-use-websocket-lite/issues"},"dist":{"shasum":"e1d9c802e149c57acd32e6df53b2872ececc82bf","tarball":"https://registry.npmjs.org/react-use-websocket-lite/-/react-use-websocket-lite-1.0.0.tgz","fileCount":18,"integrity":"sha512-BWfJ5QblArztHix0tWI96FqiRVq4kzFwDcpZt9+vag4hn4KMZaUm0F0qbZEwVnnwvurFwV7VAXmm3t4Jjm5Whg==","signatures":[{"sig":"MEUCIEb/VYFw5uj8k4jaa8vVxZ3Ph+ppGPIBW804l0DL3UHdAiEAwuTGR/Vjsl0WHqI7mgdUOhd3YRn4wlcD48sgjk1LzpU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/react-use-websocket-lite@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":29423},"type":"module","types":"./dist/index.d.ts","gitHead":"c5c63440c645b9e98342219418a8e3b77c093f24","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit"},"_npmUser":{"name":"michaelboyles","email":"michaelboyles@hotmail.co.uk"},"repository":{"url":"git+https://github.com/michaelboyles/react-use-websocket-lite.git","type":"git"},"_npmVersion":"10.9.2","description":"React Hook for WebSocket communication","directories":{},"_nodeVersion":"22.15.0","_hasShrinkwrap":false,"devDependencies":{"jsdom":"^26.1.0","vitest":"^3.1.3","typescript":"^5.8.3","@types/react":"^19.1.3","@vitest/coverage-v8":"^3.1.3","jest-websocket-mock":"^2.5.0","@testing-library/react":"^16.3.0"},"peerDependencies":{"react":"^18.0.0 || ^19.0.0"},"_npmOperationalInternal":{"tmp":"tmp/react-use-websocket-lite_1.0.0_1746545008428_0.2567099190392448","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"react-use-websocket-lite","version":"1.0.1","keywords":["react","react-hooks","websocket","websockets"],"license":"MIT","_id":"react-use-websocket-lite@1.0.1","maintainers":[{"name":"michaelboyles","email":"michaelboyles@hotmail.co.uk"}],"contributors":[{"name":"Michael Boyles","email":"michael@boyl.es"},{"url":"robtaussig.com","name":"Robert Taussig","email":"robert.taussig@gmail.com"}],"homepage":"https://github.com/michaelboyles/react-use-websocket-lite#readme","bugs":{"url":"https://github.com/michaelboyles/react-use-websocket-lite/issues"},"dist":{"shasum":"93280426bff9c4ce6614160b6a45a4f608c4980a","tarball":"https://registry.npmjs.org/react-use-websocket-lite/-/react-use-websocket-lite-1.0.1.tgz","fileCount":18,"integrity":"sha512-T1NwcGYzgTEiREzh4vOfVTgMsPRL9WtQyJbUS4duz4Vf8ADccbKs/Ii/PVFMsLhCFRQ3tG10fP5H/pIb/XMS8w==","signatures":[{"sig":"MEUCIFgcW301WrK/p/ib+/8tD3skQ79xoT9D1uJTxiQwpOE3AiEA1M3LlrXfOZqP176Xv533chDbIcGUGodFW9YmPOCc1Nc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/react-use-websocket-lite@1.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":29604},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"import":"./dist/index.js"}},"gitHead":"0293409d6fc758d7cfa733b12739ed88caa0dbc8","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit"},"_npmUser":{"name":"michaelboyles","email":"michaelboyles@hotmail.co.uk"},"repository":{"url":"git+https://github.com/michaelboyles/react-use-websocket-lite.git","type":"git"},"_npmVersion":"10.9.2","description":"React Hook for WebSocket communication","directories":{},"_nodeVersion":"22.15.0","_hasShrinkwrap":false,"devDependencies":{"jsdom":"^26.1.0","vitest":"^3.1.3","typescript":"^5.8.3","@types/react":"^19.1.3","@vitest/coverage-v8":"^3.1.3","jest-websocket-mock":"^2.5.0","@testing-library/react":"^16.3.0"},"peerDependencies":{"react":"^18.0.0 || ^19.0.0"},"_npmOperationalInternal":{"tmp":"tmp/react-use-websocket-lite_1.0.1_1746547937355_0.7097303510649418","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"react-use-websocket-lite","version":"1.1.0","keywords":["react","react-hooks","websocket","websockets"],"license":"MIT","_id":"react-use-websocket-lite@1.1.0","maintainers":[{"name":"michaelboyles","email":"michaelboyles@hotmail.co.uk"}],"contributors":[{"name":"Michael Boyles","email":"michael@boyl.es"},{"url":"robtaussig.com","name":"Robert Taussig","email":"robert.taussig@gmail.com"}],"homepage":"https://github.com/michaelboyles/react-use-websocket-lite#readme","bugs":{"url":"https://github.com/michaelboyles/react-use-websocket-lite/issues"},"dist":{"shasum":"6c7044c6bd72ac9ec1c1adbe9377bca684bbe569","tarball":"https://registry.npmjs.org/react-use-websocket-lite/-/react-use-websocket-lite-1.1.0.tgz","fileCount":21,"integrity":"sha512-wkdzIHDectuyM2aZ1X6B3bOdoqjeCyjNd6FZGMhjAeJgWkgSmj3xOKmVplEjo20mwhhLpMTF5d1r/yW8OLsAaw==","signatures":[{"sig":"MEYCIQCuXDxsoe9/zi4mS7NeW5oIvVCBsQXLgoTdp8FzR0m/vwIhAN289rUIhGU5vzghyduu7yedaPw4pr5S2gi/hkEwHsr5","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/react-use-websocket-lite@1.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":62552},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"import":"./dist/index.js"}},"gitHead":"87811193b85a2837cc8b80d5fb798c8eb3b05f65","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:99d0f47f-d3b9-48ba-8653-9b64c588c319"}},"repository":{"url":"git+https://github.com/michaelboyles/react-use-websocket-lite.git","type":"git"},"_npmVersion":"11.12.1","description":"React Hook for WebSocket communication","directories":{},"_nodeVersion":"24.14.1","_hasShrinkwrap":false,"devDependencies":{"jsdom":"^29.0.2","vitest":"^4.1.3","typescript":"^6.0.2","@types/react":"^19.2.14","@vitest/coverage-v8":"^4.1.3","jest-websocket-mock":"^2.5.0","@testing-library/react":"^16.3.2"},"peerDependencies":{"react":"^18.0.0 || ^19.0.0"},"_npmOperationalInternal":{"tmp":"tmp/react-use-websocket-lite_1.1.0_1775572913497_0.5958293037698761","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"react-use-websocket-lite","version":"1.1.1","description":"React Hook for WebSocket communication","type":"module","scripts":{"build":"tsdown src/index.ts","typecheck":"tsc --noEmit","test":"vitest run"},"peerDependencies":{"react":"^18.0.0 || ^19.0.0"},"devDependencies":{"@testing-library/react":"^16.3.2","@types/react":"^19.2.17","@vitest/coverage-v8":"^4.1.8","jest-websocket-mock":"^2.5.0","jsdom":"^29.1.1","tsdown":"^0.22.2","typescript":"^6.0.3","vitest":"^4.1.8"},"types":"./dist/index.d.mts","exports":{".":{"import":"./dist/index.mjs","types":"./dist/index.d.mts"}},"repository":{"type":"git","url":"git+https://github.com/michaelboyles/react-use-websocket-lite.git"},"keywords":["react","react-hooks","websocket","websockets"],"contributors":[{"name":"Michael Boyles","email":"michael@boyl.es"},{"name":"Robert Taussig","email":"robert.taussig@gmail.com","url":"robtaussig.com"}],"license":"MIT","bugs":{"url":"https://github.com/michaelboyles/react-use-websocket-lite/issues"},"homepage":"https://github.com/michaelboyles/react-use-websocket-lite#readme","gitHead":"7ca2678f196ba4d6911aebe8705c777d2032d320","_id":"react-use-websocket-lite@1.1.1","_nodeVersion":"24.16.0","_npmVersion":"11.17.0","dist":{"integrity":"sha512-Xl77E/DKI1GBUdpVXUq8RMGWQxvTXGgDHrNBIimP1gqPm9SsFOgBm9HGxuJ495RhjrmIxIdG99B7kfWKI5LqwA==","shasum":"1dd2234db44174c9c391867ee18de082fb594fa8","tarball":"https://registry.npmjs.org/react-use-websocket-lite/-/react-use-websocket-lite-1.1.1.tgz","fileCount":5,"unpackedSize":20501,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/react-use-websocket-lite@1.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIGX8H6mShx5EK2o8Ah6LW8S5jbw0qUIRTtDb8y9+HqtRAiEA0TZRDAb1oMM/xxM9vlpm0UhSlKY70sthAWHqeE+G6Bk="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:99d0f47f-d3b9-48ba-8653-9b64c588c319"}},"directories":{},"maintainers":[{"name":"michaelboyles","email":"michaelboyles@hotmail.co.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/react-use-websocket-lite_1.1.1_1781207736196_0.9799592234838199"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-06T15:23:28.325Z","modified":"2026-06-11T19:55:36.668Z","1.0.0":"2025-05-06T15:23:28.594Z","1.0.1":"2025-05-06T16:12:17.527Z","1.1.0":"2026-04-07T14:41:53.655Z","1.1.1":"2026-06-11T19:55:36.331Z"},"bugs":{"url":"https://github.com/michaelboyles/react-use-websocket-lite/issues"},"license":"MIT","homepage":"https://github.com/michaelboyles/react-use-websocket-lite#readme","keywords":["react","react-hooks","websocket","websockets"],"repository":{"type":"git","url":"git+https://github.com/michaelboyles/react-use-websocket-lite.git"},"description":"React Hook for WebSocket communication","contributors":[{"name":"Michael Boyles","email":"michael@boyl.es"},{"name":"Robert Taussig","email":"robert.taussig@gmail.com","url":"robtaussig.com"}],"maintainers":[{"name":"michaelboyles","email":"michaelboyles@hotmail.co.uk"}],"readme":"[![Build status](https://github.com/michaelboyles/react-use-websocket-lite/actions/workflows/build.yml/badge.svg)](https://github.com/michaelboyles/react-use-websocket-lite/actions/workflows/build.yml)\n[![Release version](https://img.shields.io/github/v/release/michaelboyles/react-use-websocket-lite?sort=semver)](https://github.com/michaelboyles/react-use-websocket-lite/releases)\n[![MIT license](https://img.shields.io/github/license/michaelboyles/react-use-websocket-lite)](https://github.com/michaelboyles/react-use-websocket-lite/blob/develop/LICENSE)\n\nThis library is a fork of [`react-use-websocket`](https://github.com/robtaussig/react-use-websocket)\nwhich has been stripped down to remove features that most people don't need. Mainly: SocketIO and EventSource support,\nand connection sharing. See the [changelog](https://github.com/michaelboyles/react-use-websocket-lite/blob/develop/CHANGELOG.md)\nfor more.\n\nThere are also some bug fixes and some improvements to reduce the number of unnecessary state changes causing re-renders.\n\nThe result is (hopefully) a library that's simpler, and easier to use in a performant way.\n\n## Usage\n\n```text\nnpm install react-use-websocket-lite\n# or\nyarn add react-use-websocket-lite\n```\n\n```tsx\nimport useWebSocket, { ReadyState } from \"react-use-websocket-lite\";\nimport { useEffect, useState } from \"react\";\n\nfunction Demo() {\n    const [messages, setMessages] = useState<string[]>([]);\n\n    const { sendMessage, readyState } = useWebSocket({\n        url: \"wss://echo.websocket.org\",\n        onMessage(event) {\n            if (typeof event.data === \"string\") {\n                setMessages(prev => [...prev, event.data]);\n            }\n        }\n    });\n\n    useEffect(() => {\n        if (readyState === ReadyState.OPEN) {\n            sendMessage(\"hello\");\n        }\n    }, [readyState])\n\n    return (\n        <pre>{ JSON.stringify(messages, null, 2) }</pre>\n    )\n}\n```\n\n## Options\n\n```typescript\ntype Options = {\n    /**\n     * The URL which will passed as the 1st argument of WebSocket's constructor\n     * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket#url}\n     */\n    url: string | (() => string | Promise<string>) | null\n    /**\n     * The protocols which will be passed as the 2nd argument of WebSocket's constructor\n     * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket#protocols}\n     */\n    protocols?: string | string[]\n    /**\n     * Whether to connect to the WebSocket\n     * @defaultValue `true`\n     */\n    connect?: boolean\n    /**\n     * Callback invoked when the WebSocket opens\n     * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/open_event}\n     */\n    onOpen?: (event: WebSocketEventMap['open']) => void\n    /**\n     * Callback invoked when the Websocket closes\n     * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close_event}\n     */\n    onClose?: (event: WebSocketEventMap['close']) => void\n    /**\n     * Callback invoked when the WebSocket receives a message\n     * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event}\n     */\n    onMessage?: (event: WebSocketEventMap['message']) => void\n    /**\n     * Callback invoked when the WebSocket closes due to an error\n     * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/error_event}\n     */\n    onError?: (event: WebSocketEventMap['error']) => void\n    /**\n     * Callback invoked when giving up because {@link Options.maxReconnectAttempts} was exceeded.\n     * @param numAttempts - The number of attempts\n     */\n    onReconnectStop?: (numAttempts: number) => void\n    /**\n     * Callback invoked immediately before the websocket attempts to connect\n     * @param attemptNum - The attempt number (first attempt will be 1)\n     */\n    onConnectAttempt?: (attemptNum: number) => void\n    /**\n     * Whether to attempt to reconnect after the WebSocket is closed\n     * @defaultValue `false`\n     */\n    shouldReconnect?: boolean | ((event: WebSocketEventMap['close']) => boolean)\n    /**\n     * The interval in milliseconds between reconnection attempts\n     * @defaultValue `5000` (5 seconds)\n     */\n    reconnectInterval?: number | ((lastAttemptNumber: number) => number)\n    /**\n     * The maximum number of retries when connecting/reconnecting. Once this\n     * limit has been exceeded, the connection will stop automatically trying\n     * to connect/reconnect.\n     *\n     * @defaultValue `undefined` (unlimited)\n     */\n    maxReconnectAttempts?: number | undefined\n    /**\n     * Whether to reconnect after an error event\n     * @defaultValue `false`\n     */\n    retryOnError?: boolean\n    /**\n     * Heartbeat behaviour. A message sent every N milliseconds\n     * @defaultValue `undefined` (no heartbeats)\n     */\n    heartbeat?: HeartbeatOptions\n    /**\n     * The connection is closed after not receiving a message for\n     * this many milliseconds\n     *\n     * @defaultValue `undefined` (no timeout)\n     */\n    messageTimeout?: number\n}\n\ntype HeartbeatOptions = {\n    /**\n     * The message to send after every {@link HeartbeatOptions.interval}. If provided as a\n     * function, the message will be created immediately before each send, allowing dynamic\n     * properties like timestamps\n     */\n    message: WebSocketMessage | (() => WebSocketMessage)\n    /**\n     * The interval between outgoing heartbeats, in milliseconds\n     */\n    interval: number\n}\n\ntype WebSocketMessage = BufferSource | Blob | string\n```\n\n## `useWebSocket` return value\n\n```typescript\ntype WebSocketHook = {\n    /**\n     * Send a websocket message.\n     * @param message the message to send\n     * @param queueable whether the message may be queued to send when\n     *   the websocket connects. Default: true\n     */\n    sendMessage: (message: WebSocketMessage, queueable?: boolean) => void\n    /** The current connection status of the websocket */\n    readyState: ReadyState\n    /** Get the native websocket. May be null, if for example {@link Options.enabled} is false */\n    getWebSocket: () => (WebSocket | null)\n}\n```\n","readmeFilename":"README.md"}