A React component for WebSocket communication designed to work seamlessly with Next.js, including server-side rendering. Version 1.0.11 is the latest stable release; the package has not been updated since 2022. It forks react-websocket and adds Next.js compatibility, with support for automatic reconnection, debug logging, and hooks-like callbacks. Package maintainer recommends it for simple live data feeds such as real-time counters or chat, but it lacks modern features like hooks or TypeScript definitions.
npm install nextjs-websocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows a minimal React component using the Websocket component to receive live numeric data and display it.
Consider migrating to a maintained library like react-use-websocket or native WebSocket with useEffect.
Add 'use client' directive at the top of the file using Websocket.
Use JSON.parse(data) inside onMessage (or handle errors).
Change import Websocket from 'nextjs-websocket' to import { Websocket } from 'nextjs-websocket'.Use require('nextjs-websocket') or configure webpack/babel for ES modules.Wrap the component in a dynamic import with { ssr: false } or move it to a client component with 'use client' directive.Ensure onMessage is a bound function (e.g., this.handleMessage.bind(this)) or use arrow function.