Dealing with multiple clicks simultaneously on mobile devices in React

I'm currently developing a Telegram mini app and I've run into an issue where users can't click on objects with more than one finger. I would like to find a way to make this possible.

My tech stack includes the latest React with Next.js and Tailwind CSS for styling.

Here's how my current setup looks:

const handleClick = () => {
    console.log(e.detail);

    const card = e.currentTarget;
    const rect = card.getBoundingClientRect();
    const x = e.clientX - rect.left - rect.width / 2;
    const y = e.clientY - rect.top - rect.height / 2;

}

<div className="cursor-pointer" onClick={handleClick}></div>

Specifically, I am looking for a solution that allows users to tap with 2-3-4 fingers simultaneously and handle these taps efficiently.

Additionally, I want users to be able to click while moving the mouse (on desktop) without needing to wait for it to stop.

It would also be helpful to retrieve information about the coordinates of these simultaneous clicks.

If you have any insights or solutions to achieve any of these requirements, please do share! Thank you!

I have tried setting up 'cursor-pointer' and handling `e.detail`, but I am unsure of what steps to take next.

Your assistance is greatly appreciated.

Answer №1

To achieve this functionality, you can utilize a touchstart event in combination with invoking your click function. It is important to check the touches property of the event to ensure that the action is only triggered when there are multiple touch-points, specifically two fingers in this scenario.

addEventListener("touchstart", (event) => {
    if (event.touches.length > 1){
        // Implement your click function here
    }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a Perfect Arc with a Consistent Fixed Focal Point

Trying to achieve a unique sunflower effect on canvas with an arc, but my geometry skills are a bit rusty. To begin, I set the origin point in the middle of the canvas as (X1, Y1). Then I determine the Mouse Position as (Xm, Ym). If I draw an imaginary l ...

Experiencing issues with running Jest tests and encountering a failed status?

As I attempt to write my first test in the app, I encounter an error message: ● Login component tests › should have 3 input fields ! expect(received).toHaveLength(expected) Expected length: 3 Received length: 0 Received object: {} 13 | 14 | ...

Can TypeScript support the use of typed streams?

When working with TypeScript and using the typings from @types/node, streams default to using the any type. While this may suffice in most cases, it is not the most optimal approach as data emitted through the data event typically has a consistent type, es ...

Extract token from the URL and then use Axios in Vue.js to send it to the POST API

Hey there, I'm in need of extracting a token from the URL http://192.168.178.25:8080/register?token=eyJhbGciOiJIUzI... and then making a POST request to the API to confirm the account. I've attempted this but encountered a SyntaxError on the ...

Utilizing PhysiJS for obtaining linear velocity at a specific point on a rotating object

Is there a way to calculate the linear velocity (relative to world space) of a point on an object in PhysiJS, utilizing the object's linear and angular velocity? I considered creating an invisible vertex on the object for this task, but it seems like ...

Troubleshooting problem with CSS alignment within Bootstrap framework

Having trouble with the alignment when using bootstrap CSS. My desired layout is as follows: Place name: dropdownbox Gender (radio-button)Male (radio-button)Female Amount Max: textbox Min: textbox Any advice on how to achieve this? ...

When using D3.js, the d3.json method may result in an Uncaught TypeError where it is unable to read the property '0' of

I lack knowledge in javascript and JSON, and I'm unsure why my code isn't functioning correctly. A portion of my JSON data is provided below: [{'Africa' : {'children':[{stuff}], 'name': 'Africa'} ...other ...

Implementing real-time updates in C# code behind for an ASP.NET variable

Recently, I devised a program in c# that scans files from the hard drive and presents that data on a webpage through asp.net. The information concerning those files is altered in the codebehind. I successfully created variables to access and exhibit the ...

What is the best approach for organizing type declaration files when using Vite in a React TypeScript application?

Currently in the process of transitioning my application from Webpack to Vite. Seeking guidance on the optimal method for including the following: /// <reference types="vite/client" /> There is an existing file types/global.d.ts, and I&ap ...

Updating the junction table in a many-to-many relationship with Sequelize

I am facing a challenge in updating a junction table with multiple ids. My goal is to update the junction table by removing rows with missing ids and creating new ones. Here is my current setup: ActorFilm.belongsTo(models.Actor, { foreignKey: 'acto ...

Is it impossible to modify the value of a cookie that has been established in JavaScript

I have an <asp:CheckBox OnClick=""> linked to a JavaScript function that sets a cookie value like this: document.cookie = "cv0_value=1"; In my .Net code-behind, I am retrieving the cookie value using the following code, and everything seems to be f ...

Select from the drop-down menu to update the displayed image

Similar Query: How to use jQuery onchange/onfocus for selecting a box to show an image? I am seeking a way to dynamically change an image based on the selected option in a dropdown with the ID "main". I found this snippet of code that retrieves text ...

Registering components globally in Vue using the <script> tag allows for seamless integration

I'm currently diving into Vue and am interested in incorporating vue-tabs into my project. The guidelines for globally "installing" it are as follows: //in your app.js or a similar file // import Vue from 'vue'; // Already available imp ...

What other strategies can I utilize to enhance my bundle and boost webpage loading time?

In my React application, I've utilized various libraries like redux, redux-form, react-router, leaflet, react-bootstrap, redux-thunk, and more. The minified bundle size is 531kb, while the vendor file stands at 5.32mb. For bundling and optimization, ...

Discovering the upcoming work schedule and day based on a provided set of working hours

I have a schedule array that outlines the working hours of a company for each day of the week. I am looking to determine if the company is currently open or closed, and if open, display the closing time. If closed at the current time, I want to show the n ...

Discovering the true width of an element using JavaScript

Hey there, I'm currently attempting to determine the exact width of a specific element and display an alert that shows this width. The code I am using is as follows: HTML Element <table cellspacing="1" cellpadding="5" style=";width:975px;border: ...

Canvas flood fill is having trouble reaching the edges

While utilizing a flood fill algorithm to fill circles drawn on the canvas, I've encountered an issue where the algorithm fails to fill right up to the edge of the circle. Here is the implementation of the algorithm based on this blog post: function ...

A quick guide on displaying the number of likes and dislikes in the React user interface immediately

Currently, I am working on integrating a like and dislike feature. Whenever a user clicks the like button, the array is updated with their like but the count is not displayed in the UI until after a refresh. import React, { useEffect, useState } from " ...

unveiling the comparison between the revealing module and object literal patterns in encapsulating code

When developing a new feature, my typical approach is to create a separate component for each one. For example, if I have a feature called abc, I would write the following JavaScript: var AbcComponent = (function(){} var initialize = function(){ }, ...

Modify the href attribute of an anchor tag that does not have a specified class or

I am currently using an event plugin that automatically links all schedule text to the main event page through anchor tags, like this: <td><a href="http://apavtcongresso.staging.wpengine.com/event/congresso-apavt-2018/">Chegada dos primeiros c ...