Skip to content

Commit

Permalink
Persist the mediaQueryList instance generated by window.matchMedia
Browse files Browse the repository at this point in the history
so that we do actually unbind our previously bound listeners.
  • Loading branch information
rtibbles committed Oct 17, 2023
1 parent 7fb3079 commit 850f895
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/useKResponsiveWindow/MediaQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ export default class MediaQuery {
constructor(query, eventHandler) {
this.query = query;
this.eventHandler = eventHandler;
this._mediaQueryList = null;
}

/**
* @returns {Object} Media query list
*/
get mediaQueryList() {
return window.matchMedia(this.query);
if (!this._mediaQueryList) {
this._mediaQueryList = window.matchMedia(this.query);
}
return this._mediaQueryList;
}

/**
Expand Down

0 comments on commit 850f895

Please sign in to comment.