0.0.2 • Published 4 years ago

react-use-sockjs v0.0.2

Weekly downloads
30
License
-
Repository
github
Last release
4 years ago

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