Answers for "stomp"

0

stomp

function App() {

 const [stompClient, setStompClient] = useState(null);

 useEffect(() => {
  //https://medium.com/practo-engineering/websockets-in-react-the-component-way-368730334eef
  const socket = SockJS(ENDPOINT);
  const stompClient = Stomp.over(socket);
  stompClient.connect({}, () => {
   stompClient.subscribe('/topic/greetings', (data) => {
    console.log(data);
   });
  });
  setStompClient(stompClient);
 }, []);

 return (
  <div> 
   <a href='#' onClick={() => {
    stompClient.send('/app/hello', {}, JSON.stringify({
     name: 'hi'
    }))
   }}>Send message</a>
  </div>
 )

}
Posted by: Guest on July-30-2021

Browse Popular Code Answers by Language