Skip to content Skip to sidebar Skip to footer

What's The Proper Way Of Binding Touchstart On React Js?

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 handl

Solution 1:

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

Solution 2:

When playing with touch events I added React.initializeTouchEvents(true) to the componentWillMount component lifecycle method and it seemed to work correctly.

varMyHeader = React.createClass({
  componentWillMount: function(){
    React.initializeTouchEvents(true);
  },
  handleTouchStart: function() {
    console.log('handleTouchStart');
  },
  render: function() {
    returnthis.transferPropsTo(
        <headeronTouchStart={this.handleTouchStart}>{title}</header>
    );
  }
};

Solution 3:

Hy, Iraê!

You have to call React.initializeTouchEvents(true) before any rendering. Check react doc here: http://facebook.github.io/react/docs/events.html#touch-events

Post a Comment for "What's The Proper Way Of Binding Touchstart On React Js?"