在React JS上绑定touchstart的正确方法是什么? [英] What's the proper way of binding touchstart on React JS?

查看:1196
本文介绍了在React JS上绑定touchstart的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习React JS,截至目前我在源代码,测试或官方文档上找不到任何示例。在文档上,据说支持 touchStart 事件,但 handleTouchStart 不起作用。

I am learning React JS and as of now I cannot find any example on the source code, tests or on the official docs. On the docs the touchStart event is said to be supported but handleTouchStart does not work.

我发现的唯一地方和实际工作的例子是反应触摸项目。

The only place I found and example that actually works was on react-touch project.

以下代码有效,但这是唯一的绑定方式吗?对我来说,它看起来像是一种廉价的解决方法。

The following code works, but is this the only way of binding? It looks like a cheap workaround for me.

var MyHeader = React.createClass({
  handleTouchStart: function() {
    console.log('handleTouchStart');
  },
  render: function() {
    return this.transferPropsTo(
        <header onTouchStart={this.handleTouchStart}>{title}</header>
    );
  }
};

实际上这样做的正确方法是什么?

What is actually the proper way of doing this?

推荐答案

自React v0.14起,你不必再手动调用 React.initializeTouchEvents(true);

Since React v0.14, you don't have to call React.initializeTouchEvents(true); manually anymore.

http://facebook.github.io/react/blog/2015/10 /07/react-v0.14.html#breaking-changes

这篇关于在React JS上绑定touchstart的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆