delegate-to
DOM Event delegate, it works great in React, too
✅Clever API
✅Zero dependence
✅React Server-side rendering compatible
✅All browsers supported
Compare with others
zenorocha/delegate is a popular library for delegate event:
Works in React.js
{ <div> <div ref="foo" /> </div>} { }
delegate-to
Switch to documentbody
Then in React.js
{ <div> <div onClick= /> </div>}
You can see the advantage in delegate-to
-
Fewer API interface (only 2 arguments)
-
Works with normal
addEventListener
-
React(.jsx) friendly
-
Flexibly, custom match condition
Installation
$ npm i --save delegate-to
Examples
{ <div> <div onClick= /> </div>} // custom match condition { <div> <div onClick= /> </div>}
API
delegate([selector || condition func], [dispatchEvent])
Browsers Supported
delegate-to
use native el.matchs
DOM API to match CSS selector
, it works on IE 9+ and All morden browsers, you can try custom match condition function if you need to work with old browsers.