Convert HTML event names to React event handler names.
npm install html-to-react-eventsEver tried working with HTML event names but needed to have the name of the related React event handler? Now you can use this library to easily retrieve the event handler name or bind to it straight away.
``bash`
npm install html-to-react-events --save
`javascript
import { convertEvent} from 'html-to-react-events';
const eventName = 'dblclick';
const reactEventHandler = convertEvent(eventName);
console.log(reactEventHandler); //Will return onDoubleClick
`
Binding a single event:
`javascript
import { bindEvent } from 'html-to-react-events';
const eventName = 'dblclick';
const MyComponent = ({onConfirm}) => (
Binding multiple events:
`javascript
import { bindEvents } from 'html-to-react-events';const eventName = 'dblclick';
const MyComponent = ({onEdit, onConfirm}) => {
const events = {
'click': onEdit,
'dblclick': onConfirm
};
return (
One click to edit.
Double click to confirm.
);
}
``