Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onTouchStart vs onClick in React?

When I was building a project, I found that component worked way I was intended when I double clicked it button that using onClick. But when I changed onClick to onTouchStart, it starts to work I intended.

But I am bit worried using this without not knowing the difference with onClick method.

Is there a specific case that I should use onTouchStart instead onClick in React.js?

like image 623
GoonGamja Avatar asked Oct 19 '25 04:10

GoonGamja


1 Answers

OnTouchStart is an event for devices with digitizer(touch devices). OnClick is an event for click (mouse) or tap (digitizer devices).

Open this Codepen on a mobile device and on desktop: http://codepen.io/blixt/pen/pgvGdK.

You will experience that the slide works in mobile but not in desktop.

You can achieve the same experience on desktop using mouse events: mouseup, mousedown and mousemove.

like image 118
Ankit Kataria Avatar answered Oct 21 '25 16:10

Ankit Kataria



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!