Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sneas/react-event-param
Pass custom param to event handler. Avoid binding.
https://github.com/sneas/react-event-param
event handler javascript parametrization react
Last synced: about 1 month ago
JSON representation
Pass custom param to event handler. Avoid binding.
- Host: GitHub
- URL: https://github.com/sneas/react-event-param
- Owner: sneas
- License: mit
- Created: 2019-02-27T18:24:15.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T17:03:00.000Z (almost 2 years ago)
- Last Synced: 2024-10-05T11:06:28.414Z (about 1 month ago)
- Topics: event, handler, javascript, parametrization, react
- Language: TypeScript
- Homepage:
- Size: 570 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-event-param
[![version](https://img.shields.io/npm/v/react-event-param.svg?style=flat-square)](http://npm.im/react-event-param)
[![MIT License](https://img.shields.io/npm/l/react-event-param.svg?style=flat-square)](http://opensource.org/licenses/MIT)Provide custom param to DOM event handler.
And avoid memory-consuming bindings or arrow functions.## Installation
```bash
npm install --save react-event-param
```## Usage Example
```javascript
import React, { Component } from "react";
import { setEventParam, getEventParam } from "react-event-param";class List extends Component {
state = {
selectedIndex: null
};onItemClick = e => {
const index = getEventParam(e.target);
this.setState({
selectedIndex: index
});
};render() {
return (
-
{{ itemText }}
{this.props.items.map((itemText, index) => (
))}
);
}
}
export default List;
```