npm.io
1.1.8 • Published 4 years ago

react-event-stream

Licence
MIT
Version
1.1.8
Deps
0
Size
8 kB
Vulns
0
Weekly
0

react-event-stream is custom a React Hook that wraps built-in EventSource object.

npm CodeFactor npm bundle size NPM npm JavaScript Style Guide

react-event-stream simplifies to use Server Sent Events with built-in EventSource in your react application.

More information about server-sent-events.

Install

react-event-stream uses rxjs as peerDependency, so you have to install rxjs with react-event-stream.

by using npm:

$ npm i react-event-stream rxjs

by using yarn:

$ yarn add react-event-stream rxjs

Usage

import React from 'react'
import useEventStream from 'react-event-stream';

const Example = () => {
    const value = useEventStream('http://localhost:8080/sse', 1000);

    return (
        <>
            {JSON.stringify(value)};
        </>
    );
};

export default Example;

Made with

License

MIT enesusta