onclick hold react
import { useState, useEffect, useCallback } from 'react';
export default function useLongPress(callback = () => {}, ms = 300) {
const [startLongPress, setStartLongPress] = useState(false);
useEffect(() => {
let timerId;
if (startLongPress) {
timerId = setTimeout(callback, ms);
} else {
clearTimeout(timerId);
}
return () => {
clearTimeout(timerId);
};
}, [callback, ms, startLongPress]);
const start = useCallback(() => {
setStartLongPress(true);
}, []);
const stop = useCallback(() => {
setStartLongPress(false);
}, []);
return {
onMouseDown: start,
onMouseUp: stop,
onMouseLeave: stop,
onTouchStart: start,
onTouchEnd: stop,
};
}
Also in JavaScript:
- jquery order by specific order
- how to have a function inside useeffect
- expect any function jest
- html define javascript variable
- cdnjs smeantic ui
- onload fetch data using ajax laravel
- javascript to help find overflow elements
- slide when mouse over gadget jquery
- how to convert whole strig in lowercase in js
- const { message } = new assert.AssertionError({ actual: 1, expected: 2, operator: 'strictEqual' });
- jquery ajax CORS
- jquery get current row value
- jquery how to expand select
- angular json and cli json file
- set up background process in express app
- id condition with ngfor in angular 10
- mongoose connection nodejs
- js canvas draw image
- jquery populate select from json
- add javascript
- json data example
- javascript location object
- javascript disable scrolling on body
- javascript iterate object key values