Any React application is likely going to share the same event handling logic for different components. For example, in response to a button click, the component should sort a list of items. It's these types of generic behaviors that belong in their own modules so that several components can share them. Let's implement a component that uses a generic event handler function:
import React, { Component } from "react";
import reverse from "./reverse";
export default class MyList extends Component {
state = {
items: ["Angular", "Ember", "React"]
};
onReverseClick = reverse.bind(this);
render() {
const {
state: { items },
onReverseClick
} = this;
return (
<section>
<button onClick={onReverseClick}>Reverse</button>
<ul>
{items.map((v, i) => (
<li key={i}>{v}</li>
))}
</ul>
</section...