←back to thread

218 points mdhb | 3 comments | | HN request time: 0s | source
Show context
ericyd ◴[] No.44392324[source]
> React doesn't provide a way to explicitly bind to properties and events of DOM elements, or provide directives that apply to an element.

I didn't understand this part, can anyone shed light? What is different between what's being described here and what React does with event listeners, etc?

replies(2): >>44392581 #>>44392634 #
1. bevr1337 ◴[] No.44392634[source]
> React doesn't provide a way to explicitly bind to properties and events of DOM elements

We can nitpick this point because react has had a ref API for at least 5 years now. Given a ref, all DOM API are available. For events, SyntheticEvent will refer to a native event if it exists.

The SyntheticEvent abstracts vendor discrepancy. Under the hood, react can apply some optimization too.

https://legacy.reactjs.org/docs/events.html https://react.dev/reference/react-dom/components/common#reac...

replies(1): >>44392679 #
2. MrJohz ◴[] No.44392679[source]
The synthetic event also adds its own abstractions though. For example, the `onChange` handler in React behaves very differently to the native DOM `change` event.
replies(1): >>44393539 #
3. bevr1337 ◴[] No.44393539[source]
And then some. Switching to react-native or other render targets can also be a doozy. Hopefully the references clarify all the features.