Skip to content
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

FIX - click + rerender + click being interpreted as two single clicks instead of one double click #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TomerHir
Copy link

Steps to reproduce:

  1. perform a click
  2. cause a re-render
  3. perform a second click

Expected result:
Double-click callback will fire

Actual result:
Two click callbacks fire

function Demo() {
  const buttonRef = useRef<HTMLButtonElement>(null);
  const [, setCounter] = useState(0);

  useDoubleClick({
    onDoubleClick: () => console.log('dbclick'), // will never fire
    onSingleClick: () => console.log('single click'), // will fire twice on double-clicking
    ref: buttonRef,
    latency: 300,
  });
  return (
    <button onClick={() => setCounter((x) => x + 1)} ref={buttonRef}>
      click me
    </button>
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants