ReactTraining / react-media

CSS media queries for React
MIT License
2.44k stars 115 forks source link

deprecated addListener and removeListener update #135

Closed Maxim-Mazurok closed 5 years ago

Maxim-Mazurok commented 5 years ago

addListener and removeListener are deprecated in a favor of addEventListener and removeEventListener.

From MediaQueryList/addListener

This (addListener) is basically an alias for EventTarget.addEventListener(), for backwards compatibility purposes.

They are supported by all major browsers: EventTarget/addEventListener

BTW, TSLint is producing the following error when trying to use addListener:

ERROR: /app/Component.tsx:xx:xx - addListener is deprecated.
edorivai commented 5 years ago

Thanks @Maxim-Mazurok!

Maxim-Mazurok commented 5 years ago

So, I just found out that it's not supported in Safari on Mac OS. I tried 13.0 and 13.1 (TP). Both of them only know addListener for MediaQueryList, unfortunately. It's not working on my iOS devices also (iOS 12.4). You might want to revert this change or make it part of the major release, introducing a breaking change. Sorry about that...

edorivai commented 5 years ago

Well that's weird, I glanced over the browser compatibility source you shared and it looked pretty good. Thanks for the heads up, at least I hadn't published to npm yet 😁

Maxim-Mazurok commented 5 years ago

Yeah, they support addEventListener in general, but not for the MediaQueryList, unfortunately. Here's a relevant issue: https://github.com/microsoft/TypeScript/issues/32210

BTW, the best way to see the browser support for these particular methods is to go to MDN:MediaQueryList#Browser_compatibility and check out MediaQueryList inheriting from EventTarget section of the table. Thanks to https://github.com/mdn/browser-compat-data/pull/3674 for making this contribution.

edorivai commented 5 years ago

Reverted, thanks again for the heads up :pray:

Maxim-Mazurok commented 4 years ago

Good news for Safari: addEventListener was added for MediaQueryList in Safari 14.0 TP (Release 109 (Safari 14.0, WebKit 15610.1.17.2))