Skip to content

Instantly share code, notes, and snippets.

@S-codes14
Created March 31, 2022 02:57
Show Gist options
  • Select an option

  • Save S-codes14/961c655d570c53b082e7bf9eb2ddca67 to your computer and use it in GitHub Desktop.

Select an option

Save S-codes14/961c655d570c53b082e7bf9eb2ddca67 to your computer and use it in GitHub Desktop.
React Router onclick workaround
/**
* React Router onclick workaround
* @example <div {...OnClick(onClick)}/>
*/
const OnClick = (() => {
let clickTime = 0;
let pos = { x: 0, y: 0 };
return onClick => ({
onMouseDown: ({ nativeEvent: e }) => { clickTime = Date.now(); pos.x = e.x; pos.y = e.y; },
onMouseUp: ({ nativeEvent: e }) => { Date.now() - clickTime < 500 && pos.x === e.x && pos.y === e.y && e.which === 1 && onClick() },
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment