/react-use-sockjs

React hooks for SockJS-client with STOMP messaging protocol.

Primary LanguageTypeScript

react-use-sockjs

React hooks for SockJS-client with STOMP messaging protocol.

安装

npm install --save react-use-sockjs

例子

import React, { useState } from 'react';
import useSockjs from 'react-use-sockjs';

export default () => {
  const [data, setData] = useState({});

  const { sendMessage } = useSockjs({
    url: 'http://localhost/ws',
    topics: ['/user'],
    onMessage: (body, destination) => {
      console.log(body, destination);
      setData(body);
    },
  });

  return <div>test</div>;
};

API

Auto generated docs available here.

License

This project is licensed under the MIT License - see the LICENSE file for details