Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

double click react

const [nrTaps, setNrTaps] = useState<number>(0);
const [startDate, setStartDate] = useState<number>(Date.now());

  const touchStart = () => {
    if (nrTaps >= 1 && Date.now() - startDate < 500) {
      setStartDate(Date.now());
      setNrTaps(0);

      // double tap
    } else {
      setStartDate(Date.now());
      setNrTaps(prevNr => prevNr + 1);

      // single tap;
    }
};
 
PREVIOUS NEXT
Tagged: #double #click #react
ADD COMMENT
Topic
Name
5+4 =