https://github.com/codewell/on-event
Trigger function on event and pass the event as argument to the function
https://github.com/codewell/on-event
Last synced: 6 days ago
JSON representation
Trigger function on event and pass the event as argument to the function
- Host: GitHub
- URL: https://github.com/codewell/on-event
- Owner: codewell
- Created: 2020-11-20T08:59:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-20T09:44:02.000Z (over 5 years ago)
- Last Synced: 2025-02-22T07:31:50.915Z (over 1 year ago)
- Language: JavaScript
- Size: 80.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @codewell/on-event
Wrapper function that passes JavaScript event as first parameter to a function when the event is triggered.
```JavaScript
const onEvent = (func, ...args) => (event) => func(event, ...args);
```
## Installation
```
npm install @codewell/on-event
```
## Basic Usage
```JavaScript
import onEvent from '@codewell/on-event';
const handleClickEvent = (event) => {
// Handle the click event...
};
const SomeComponent = (props) => (
);
```
```JavaScript
import onEvent from '@codewell/on-event';
const handleInputChange = (event, label) => {
const inputValue = event.target.value;
return `${label}: ${inputValue}`;
// "first name: some input value..."
}
const SomeComponent = (props) => (
)
```