logoalt Hacker News

ericydyesterday at 11:07 PM2 repliesview on HN

> 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

krebbyyesterday at 11:48 PM

I think this is referring to the fact that React uses synthetic event listeners - it's cheaper to bind an event listener once at the root and do your own element matching than it is to continuously bind and unbind listeners.

https://react.dev/reference/react-dom/components/common#reac...

bevr1337today at 12:01 AM

> 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...

show 1 reply