-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No double click detection with useEffect #24
Comments
can you create small demo app to check this problem? |
Late but I was exploring this recently: The hook has no dependency array in it's useEffect so your |
Does this sandbox work for you? https://codesandbox.io/s/use-double-click-f7e33?expanddevtools=1&fontsize=14 Feel free to provide a repro of it not working |
this pr will solve your issue once it's verified as production-ready: additionally, you could THEORETICALLY add this component to your code and use it instead of directly calling /**
* component that handles a rerender in the middle of the double click event.
* yes.
* seriously.
*/
const DoubleClickComponent = memo(function DoubleClickComponent<TClickableHTML extends HTMLElement>({
onSingleClick,
onDoubleClick,
clickableRef,
latency,
}: {
onSingleClick: (e: MouseEvent) => void;
onDoubleClick: (e: MouseEvent) => void;
clickableRef: MutableRefObject<TClickableHTML>;
latency?: number;
}) {
useDoubleClick({
onSingleClick,
onDoubleClick,
ref: clickableRef,
latency: latency,
});
return null;
}); |
I am trying to detect double clicks and single clicks on buttons.
This function works perfectly, but when I try to change a state variable, the useDoubleClick hooks stops to detect double clicks.
What am I doing wrong?
The text was updated successfully, but these errors were encountered: