Re:Cash: An absurdly small jQuery alternative for modern bro...
by kccqzy on Saturday November 02, 2024 @06:00PM
(#42029503)
I recently attempted to remove React as a dependency just to see what would happen. It turns out different browsers are still incredibly inconsistent when it comes to event handling. For example the select event on an <input> element somehow doesn't fire at all on Safari during my test, and doesn't fire when the caret is merely moved on some browsers. Using just the native browser functions isn't just fine, even if you don't need all the React features like components or state or props. It turns out React DOM is valuable as it papers over browser differences.
[ Parent
| on HN ]
Re:Cash: An absurdly small jQuery alternative for modern bro...
by divbzero on Saturday November 02, 2024 @06:11PM
(#42029567)
I haven’t tested myself, but according to MDN the select event on <input> elements should be supported by Safari?
https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputEl...
Re:Cash: An absurdly small jQuery alternative for modern bro...
by kccqzy on Saturday November 02, 2024 @06:21PM
(#42029627)
The MDN page you linked to includes a nice selection logger example. It just doesn't work on my Safari (iOS).
Re:Cash: An absurdly small jQuery alternative for modern bro...
by chrismorgan on Saturday November 02, 2024 @10:48PM
(#42030858)
And does an equivalent in React work? Because I don't believe React does any of the papering-over you describe. My understanding (as a non-user) is that React does, logically, essentially nothing special around event handling.
Re:Cash: An absurdly small jQuery alternative for modern bro...
by kccqzy on Saturday November 02, 2024 @11:23PM
(#42030954)
I don't remember off the top of my head whether this specific example works in React as I'm not next to a computer. But I remember reading React source code and finding a whole lot of code to handle the select event. (Just found it by doing a GitHub code search on my phone https://github.com/facebook/react/blob/7c8e5e7ab8bb63de91163...)
In general React has its own event handling code. For one in React the user doesn't even deal with the browser native DOM events but React synthetic events. React also readily creates brand new synthetic events from other browser events. React also sometimes gives different names or behaviors to browser events; the most famous example is that the React onChange event is roughly equivalent to the browser onInput event, but absolutely different from the browser onChange event.
Re:Cash: An absurdly small jQuery alternative for modern bro...
by chrismorgan on Saturday November 02, 2024 @11:48PM
(#42031027)
Good to know, thanks. I knew it made synthetic events, but thought it was all still 1:1. I see I was completely wrong. I gotta say, yuck. Don't like it, wish they'd taken a more polyfill-like approach.
Re:Cash: An absurdly small jQuery alternative for modern bro...
by Izkata on Sunday November 03, 2024 @01:37AM
(#42031489)
IIRC they do that to deal with browser differences and be consistent with things like event bubbling. Probably other benefits as well but that's the one I'm fairly sure I remember from years ago.
Re:Cash: An absurdly small jQuery alternative for modern bro...
by fiddlerwoaroof on Saturday November 02, 2024 @11:25PM
(#42030959)
There are a couple of edge cases I forget at the moment where react event handlers intentionally behave differently from the DOM handlers with the same name.