useXStream ๐ฑ โ
Introduction โ
This hook function allows users to more conveniently control streaming requests. It provides initiate request
, cancel request
, returns loading
request state, returns SSE protocol real-time data stream
, and returns request error
information.
๐ Info
Currently only SSE and SIP protocol requests have been tested, other protocols are yet to be tested. If you have good ideas or discoveries, you are welcome to join the community group ๐จโ๐ฉโ๐งโ๐ง Community Group, contact us, share solutions, submit issues and PRs. Please read the ๐ Development Guide for submission specifications.
Code Examples โ
๐ Warning
The parsing rules of this hook are consistent with ant-design-x, all handled internally. Feel free to switch and use
sseEventPart 'event: message\ndata: {"id":"${i}","content":"${contentChunks[i]}"}\n\n'
// Default stream separator (uses two newlines to split a stream data)
const DEFAULT_STREAM_SEPARATOR = '\n\n';
// Default part separator (uses a single newline to break current data)
const DEFAULT_PART_SEPARATOR = '\n';
// Default key-value separator (uses colon)
const DEFAULT_KV_SEPARATOR = ':';
Returned Hooks โ
Property | Description | Type |
---|---|---|
startStream | Start request in stream mode | ({readableStream, transformStream}) => void |
cancel | Cancel streaming request | () => void |
loading | Is streaming data loading | boolean |
data | Real-time streaming data | string |
error | Streaming request error info | string |