Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
react-stomp-hooks
Advanced tools
A react library to manage a application wide STOMP connection via SockJS or Websockets.
npm install --save react-stomp-hooks
See also the supplied example project, and its sourcecode.
import React from "react";
import { StompSessionProvider, useSubscription } from "react-stomp-hooks";
const App = () => {
return (
//Initialize Stomp connection, will use SockJS for http(s) and WebSocket for ws(s)
//The Connection can be used by all child components via the hooks or hocs.
<StompSessionProvider
url={"https://stream.elite12.de/api/sock"}
//All options supported by @stomp/stompjs can be used here
>
<SubscribingComponent />
<SendingMessages />
</StompSessionProvider>
);
};
function SubscribingComponent() {
const [lastMessage, setLastMessage] = useState("No message received yet");
//Subscribe to /topic/test, and use handler for all received messages
//Note that all subscriptions made through the library are automatically removed when their owning component gets unmounted.
//If the STOMP connection itself is lost they are however restored on reconnect.
//You can also supply an array as the first parameter, which will subscribe to all destinations in the array
useSubscription("/topic/test", (message) => setLastMessage(message.body));
return <div>Last Message: {lastMessage}</div>;
}
export function SendingMessages() {
//Get Instance of StompClient
//This is the StompCLient from @stomp/stompjs
//Note: This will be undefined if the client is currently not connected
const stompClient = useStompClient();
const sendMessage = () => {
if (stompClient) {
//Send Message
stompClient.publish({
destination: "/app/echo",
body: "Echo 123",
});
} else {
//Handle error
}
};
return <Button onClick={sendMessage}>Send Message</Button>;
}
MIT © Sven Kirschbaum
FAQs
A react library to interact with a stomp connection via hooks
We found that react-stomp-hooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.