2

It seems like onClick doesn't quite work with mobile, however it works fine on a desktop browser. What is the best way to do this on mobile - know when an element is pressed?

Here's how I'm using it in my return statement:

    ...
    return (
      <div>
        <div 
          className={"bus-route-number " + this.props.data.busNumber} 
          onClick={this.toggleShowDestination}
        >
          <h1>{this.props.data.busNumber}</h1>
          <h4>{this.props.data.fullRoute}</h4>
        </div>
        {destinations}
      </div>
    )
    ...
dace
  • 5,819
  • 13
  • 44
  • 74

1 Answers1

7

You will have to use touch events. In order to enable touch events, you will have to run the following before rendering any component.

React.initializeTouchEvents(true)

More information here. There are similar questions on SO asking the same question - one of them here shows an example usage.

Community
  • 1
  • 1
Abhishek Jain
  • 2,957
  • 23
  • 35