react-event-param
v1.0.1
Published
Provide custom param for DOM event handler. Avoid memory-consuming bindings or arrow functions.
Downloads
3
Readme
react-event-param
Provide custom param for DOM event handler. And avoid memory-consuming bindings or arrow functions.
Installation
npm install --save react-event-param
Usage Example
import React, { Component } from "react";
import { setEventParam, getEventParam } from "react-event-param";
class ItemList extends Component {
state = {
selectedIndex: null
};
onItemClick = e => {
const index = getEventParam(e.target);
this.setState({
selectedIndex: index
});
};
render() {
return (
<ul>
{this.props.items.map((itemText, index) => (
<li
key={index}
{...setEventParam(index)}
onClick={this.onItemClick}
>
{{ itemText }}
</li>
))}
</ul>
);
}
}
export default ItemList;