A React component that wraps SockJS-client with the STOMP messaging protocol for real-time WebSocket communication. Current stable version is 5.1.0, released in January 2021, with sporadic updates focusing on dependency bumps and bug fixes. It provides a declarative way to connect to STOMP over SockJS endpoints, supporting automatic reconnection, topic subscriptions, and message handling. Differentiators include integration with Spring Boot backends and a simple component-based API, but it is lightly maintained and may not see frequent updates.
npm install react-stompNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage with a class component, subscribing to a topic and displaying messages.
Ensure your onMessage handler can handle both JSON objects and plain strings.
Upgrade to 5.0.0+ which uses getDerivedStateFromProps or other patterns.
Upgrade to 5.1.0+ if subscribing to multiple topics with headers.
Use callback ref and call sendMessage in componentDidMount or after connection established via onConnect.
Run 'npm install stompjs' or 'npm install @stomp/stompjs' (the latter is a fork, but react-stomp expects the original).
Verify the server URL includes '/ws' or the correct SockJS endpoint, and that the server supports STOMP.