react-event-param
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

react-event-param

version MIT License

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;
 

Dependencies (0)

    Dev Dependencies (12)

    Package Sidebar

    Install

    npm i react-event-param

    Weekly Downloads

    2

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    8.11 kB

    Total Files

    19

    Last publish

    Collaborators

    • sneasio