Created
March 31, 2022 02:57
-
-
Save S-codes14/961c655d570c53b082e7bf9eb2ddca67 to your computer and use it in GitHub Desktop.
React Router onclick workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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