0.0.11 • Published 1 year ago

sse-client-sdk v0.0.11

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

这是一个简单的 sse sdk。做了非常简单的封装,方便开发人员使用

简单使用

import SSESdk from 'sse-client-sdk'

// SSESdk 实例化
const SSE = new SSESdk(url, options);

// 订阅来自服务端的消息
SSE.subscribe("message", (data) => {
  console.log("receive message from server", data);
});

// 取消订阅
SSE.unsuscribe();

在 React 中使用

import SSEClient from 'sse-client-sdk'

const sse = new SSEClient(url, options)

function Example() {
  const [count, setCount] = useState(0)
  
  useEffect(() => {
    sse.subscribe('message', data => {
      setCount(data)
    })
    
    return () => {
      sse.unsubscribe()
    }
  }, [])
  
  return <div>{count}</div>
}

API

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.3

1 year ago