react-fetch-streams
A react hook for using the Streams API with the Fetch API to stream data from a server.
Table of Contents
Installation
You can install this package from NPM:
npm add react-fetch-streams
Or with Yarn:
yarn add react-fetch-streams
CDN
For CDN, you can use unpkg:
https://unpkg.com/react-fetch-streams/dist/index.min.js
The global namespace for react-fetch-streams is reactFetchStreams
:
Usage
Stream some data from some server:
import React useCallback useState from 'react';import useStream from 'react-fetch-streams'; const MyComponent = { const data setData = ; const onNext = ; ; return <React.Fragment> datamyProp </React.Fragment> ;};
You can also pass the fetch request init props using fetchParams
:
import React useCallback useState from 'react';import useStream from 'react-fetch-streams'; const fetchParams = mode: 'cors' const MyComponent = { const data setData = ; const onNext = ; ; return <React.Fragment> datamyProp </React.Fragment> ;};
For more examples, please check the tests.
Browser Support
You can expect this hook to work wherever the following APIs are supported:
Check browserslist.dev for an overview.
Contribute
If you wish to contribute, please use the following guidelines: