Edit
Facebook decided to not add support for defining custom event types and recommend you to use something like react-tappable so you can write something like <Tappable onTap={}>
.
Facebook’s working on a solution in the form of TapEventPlugin
, but it won’t be made available until they make some decisions.
If you’re reading this you’re probably working on a project that can’t wait until they figure out how they want to publish it.
This repo is for you: https://github.com/zilverline/react-tap-event-plugin
When Facebook solves #436 and #1170, this repo will disappear.
This solution works for React 0.14.x and 15.x.
npm i -S react-tap-event-plugin
Example of usage:
var React = require("react");
var ReactDOM = require("react-dom");
injectTapEventPlugin = require("react-tap-event-plugin");
injectTapEventPlugin();
var Main = React.createClass({
render: function() {
return (
<a
href="#"
onTouchTap={this.handleTouchTap}
onClick={this.handleClick}>
Tap Me
</a>
);
},
handleClick: function(e) {
console.log("click", e);
},
handleTouchTap: function(e) {
console.log("touchTap", e);
}
});
ReactDOM.render(<Main />, document.getElementById("container"));
Note that with the injector, you will probably need to use only onTouchTap
(and not onClick
anymore).