@alexsandersarmento/react-native-event-emitter
Version:
**@alexsandersarmento/react-native-event-emitter** is a simple library for handling custom events in React Native applications.
82 lines (48 loc) • 1.92 kB
Markdown
**@alexsandersarmento/react-native-event-emitter** is a simple library for handling custom events in React Native applications.
To install the library, you can run the following command:
```
npm install @alexsandersarmento/react-native-event-emitter
```
or
```
yarn add @alexsandersarmento/react-native-event-emitter
```
The library provides the following functions for event handling:
Adds an event listener for the specified event name. The listener will be called whenever the event is triggered.
Example usage:
```javascript
import { addListener } from '@alexsandersarmento/react-native-event-emitter';
const handleEvent = (param1, param2) => {
// Logic to handle the event
};
addListener('myEvent', handleEvent);
```
Triggers the event with the specified name, passing additional parameters. All registered listeners for the event will be called with the provided parameters.
Example usage:
```javascript
import { notify } from '@alexsandersarmento/react-native-event-emitter';
notify('myEvent', 'param1', 'param2');
```
Removes an event listener for the specified event name.
Example usage:
```javascript
import { removeListener } from '@alexsandersarmento/react-native-event-emitter';
removeListener('myEvent');
```
Removes all event listeners.
Example usage:
```javascript
import { removeAllListeners } from '@alexsandersarmento/react-native-event-emitter';
removeAllListeners();
```
Contributions are welcome! Feel free to open issues and submit pull requests to enhance the library.
This library is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.