Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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 (


    {this.props.items.map((itemText, index) => (

  • {{ itemText }}

  • ))}

);
}
}

export default List;

```