|
Download react-use/docs/useLongPress.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useLongPress.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useLongPress.md
-
curl -L -o useLongPress.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useLongPress.md
1.07 kB
useLongPress
React sensor hook that fires a callback after long pressing.
Usage
import { useLongPress } from 'react-use';
const Demo = () => {
const onLongPress = () => {
console.log('calls callback after long pressing 300ms');
};
const defaultOptions = {
isPreventDefault: true,
delay: 300,
};
const longPressEvent = useLongPress(onLongPress, defaultOptions);
return <button {...longPressEvent}>useLongPress</button>;
};
Reference
const {
onMouseDown,
onTouchStart,
onMouseUp,
onMouseLeave,
onTouchEnd
} = useLongPress(
callback: (e: TouchEvent | MouseEvent) => void,
options?: {
isPreventDefault?: true,
delay?: 300
}
)
callback— callback function.options?— optional parameter.isPreventDefault?— whether to callevent.preventDefault()oftouchendevent, for preventing ghost click on mobile devices in some cases, defaults totrue.delay?— delay in milliseconds after which to calls provided callback, defaults to300.