Why do MediaQueryLists make me feel so dirty?
I've been looking at how to implement media queries in my js, and while they work, they just leave me feeling... ugh.
I know
window.matchMedia()
returns a MediaQueryList
(mql), an object which has a property matches
, and has an onChange
listener.
So in an arbitrary view I'll call the following to get all the mql objects for my breakpoints
this._mqls = getMediaQueryLists(this._setLeft)
and then in the callback I'll check for the screen sizes
Is this really the right way to do it? I guess I can use another helper to get the size (which would make it feel a little cleaner), but still 🤢2 Replies