🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More →
Socket
Book a DemoSign in
Socket

react-stomp-client

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-stomp-client

A React STOMP client

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source

ReactStompClient

A simple STOMP message client for React. It will connect to the provided endpoint on mount, followed immmediately by a subscription to the provided topic. The connection gets cleaned up on unmount.

Easily testable via mock-stomp-broker!

Supports TypeScript.

Installing

npm install --save react-stomp-client

Usage example

import React, { Component } from "react";
import StompClient from "react-stomp-client";

class MyComponent extends Component {
  constructor(props) {
    this.state = {
      latestMessage: null
    };

    this.handleMessage = this.handleMessage.bind(this);
  }

  handleMessage(stompMessage) {
    this.setState({
      latestMessage: stompMessage
    });
  }

  render() {
    const { latestMessage } = this.state;
    return (
      <StompClient
        endpoint="ws://localhost:8888/websocket"
        topic="my-topic"
        onMessage={this.handleMessage}
      >
        <div>
          {latestMessage
            ? `Latest message received: ${latestMessage}`
            : "No message received yet"}
        </div>
      </StompClient>
    );
  }
}

Props

PropRequired?Description
endpointYesThe STOMP endpoint to connect to. The server should be up and ready to speak STOMP via WebSocket (the protocol should be either ws or wss).
topicNoThe STOMP topic to subscribe to. When no topic is provided, no subscription attempt is made.
onMessageNoThe callback to invoke when a STOMP message arrives.
childrenNoAny React component subtree. Use this to tie the together the lifecycles of the StompClient and any components that depend on data from it.
reconnectDelayNoThe delay in ms to wait before attempting to reconnect to the endpoint after a connections is interrupted. Defaults to 3000.
heartbeatIncomingNoThe heartbeat frequency in ms to request from the server. Defaults to 30000.
heartbeatOutgoingNoThe heartbeat frequency in ms to send to the server. Defaults to 30000.

Keywords

stomp

FAQs

Package last updated on 11 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts