Event handling is different between Preact and React
See original GitHub issueReproduction
There are two code sandboxes implementing the same thing in Preact and React
- Preact: https://hlg2t.csb.app/
- React: https://zy55p.csb.app/
Steps to reproduce
- Click on “Expand me”
- Click on “close”
Expected Behavior
The panel should close (and it does in React)
Actual Behavior
The panel does not close in Preact
This seem to be related to the way these frameworks handle events. React uses event delegation and Preact applies direct event listeners. Hence the click
event bubbles up and reaches the panel root when it already was re-rendered, which breaks the toggle implementation.
I found a similar issue https://github.com/preactjs/preact/issues/838 but since that one was already closed as resolved I opened a new one.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Differences to React - Preact
Preact uses the browser's native addEventListener for event handling. See GlobalEventHandlers for a full list of DOM event handlers. A full events ...
Read more >Preact vs. React: A Quick Comparison - HackerNoon
Event Handling: React implements its own synthetic event system for event handling, reducing app performance, while Preact has no synthetic ...
Read more >Preact vs. React | Syncfusion Blogs
The primary difference between React and Preact is that React uses synthetic events, which are wrapped around the actual events that React ...
Read more >React vs Preact vs Inferno - DEV Community
Preact · There is no synthetic event system. React ships its own (very heavy) Synthetic Event system that offers a host of benefits...
Read more >React Js Vs Preact: Application Development Made Easier
Preact, on the other hand, renders more quickly. ... React uses its own synthetic event system for event handling, which reduces app performance, ......
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
This is fixed with switching to
setTimeout
for debouncing as well, we should include this or an alternative scheduler for 11 https://codesandbox.io/s/cocky-star-bw9sgv?file=/src/index.jsYou could also try doing:
You can adjust that first check to just target the button you like