6.1.0 • Published 2 years ago
readable-hook v6.1.0
Readable Hook
React hooks for wrangling ReadableStreams.
Installation
npm i readable-hook --saveUsage
useStreamingQuery
const MyComponent: FC = () => {
const [{ value }, triggerQuery] = useStreamingQuery('path/to/api/endpoint');
return (
<div>
{value}
<button onClick={fetchStreamingData} />
</div>
);
};useStreamingMutation
Allows synchronizing state with a mutation endpoint that returns a streaming response. Has a few different ways to pass parameters (at init, and at mutation trigger).
const MyComponent: FC = () => {
const [{ value, isStreaming, done }, triggerMutation] = useStreamingMutation('path/to/api/endpoint', {
// params that can be passed during initialization
});
return (
<div>
{value}
<input onSubmit={e => triggerMutation({
params: {
inputValue: e.target.value
},
onDone: () => console.log("Done streaming")
})} />
</div>
);
};useReadableHook
Allows synchronizing state with a ReadableStream.
Check this for a working example.
const MyComponent: FC<{ readableStream: ReadableStream }> = ({ readableStream }) => {
const [{ value }, synchronize] = useReadable(async () => readableStream, 100);
return (
<div>
{value}
<button onClick={synchronize} />
</div>
);
};6.1.0
2 years ago
6.0.2
2 years ago
6.0.1
2 years ago
6.0.0
2 years ago
5.0.0
3 years ago
4.0.0
3 years ago
3.0.3
3 years ago
3.0.2
3 years ago
3.0.1
3 years ago
2.3.0
3 years ago
2.2.0
3 years ago
2.1.3
3 years ago
2.1.2
3 years ago
2.1.1
3 years ago
2.1.0
3 years ago
2.0.0
3 years ago
1.1.0
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago