onClick not invoked if `onMouseDown` is present and updates state
See original GitHub issueLet me start by saying that this is a very weird bug. I tried investigating your source code and I could not find anything that would possible lead to this.
It also happens if ouMouseUp
, onMouseOver
are provided.
Version
2.1.1
This bug happens with or without the babel plugin.
Reproduction
https://codesandbox.io/s/mZz51wGPG
Steps to reproduce
Just add a onMouseDown and onClick together where the onMouseDown update the react state.
const TestDiv = styled.div``;
<TestDiv onMouseDown={() => this.setState({ hi: true })} onClick={() => alert('hi')}>click me, it does not work</TestDiv>
Expected Behavior
onClick is called
Actual Behavior
onClick is not called
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
onMouseDown event in react does not trigger state changes ...
I made a simple demo here and it seems to work fine with both onClick and onMouseOver . Click the text and check...
Read more >onMouseDown event in react does not trigger state changes ...
Coding example for the question onMouseDown event in react does not trigger state changes but onClick does-Reactjs.
Read more >Mouse events - The Modern JavaScript Tutorial
Mouse event types. We've already seen some of these events: mousedown/mouseup: Mouse button is clicked/released over an element.
Read more >ASP.NET Core Blazor event handling - Microsoft Learn
Learn about Blazor's event handling features, including event argument types, event callbacks, and managing default browser events.
Read more >React: Event Bubbling and Capturing - Robin Wieruch
mousedown ; mouseup; click. This particular event list is displayed in its order of execution. So if there are mouseup and a click...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FYI. In my case I was doing stuff like this:
Based on your findings and the documentation, I replaced it to be something like this (which makes totally sense):
I’m sharing here just in case hits a similar problem 👍
nicely done. thanks for the quick follow up.