2.0.0 • Published 10 months ago

react-socket-event v2.0.0

Weekly downloads
13
License
MIT
Repository
github
Last release
10 months ago

npm-version

Installation

yarn add react-socket-event

Quick Start

import SocketEvent from 'react-socket-event';

useEffect(() => {
    const removeListener = SocketEvent.on('my-event', (data) => {
        console.log(data);
    });

    return removeListener; //remove listener on unmount the component
}, []);

SocketEvent.emit('my-event', 'hello, world');
SocketEvent.clear('my-event'); //remove all listeners to 'my-event'

SocketEvent.clearAll(); //remove all listeners

SocketEvent.getAllListeners(); //return all listeners [{id, chanel, cb, key}]

Overwrite repeated listeners

import SocketEvent from 'react-socket-event';

SocketEvent.on(
    'my-event',
    (data) => {
        console.log(data);
    },
    'MY_UNIQUE_LISTENER'
);

// overwrites the previous listener avoiding multiple listeners
SocketEvent.on(
    'my-event',
    (data) => {
        console.log(data);
    },
    'MY_UNIQUE_LISTENER'
);

// will not overwrite
SocketEvent.on(
    'my-event',
    (data) => {
        console.log(data);
    },
    'MY_OTHER_LISTENER'
);

SocketEvent.emit('my-event', 'hello, world');
2.0.0

10 months ago

1.0.1

2 years ago

1.0.0

2 years ago

0.4.1

3 years ago

0.3.1

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago